473,803 Members | 3,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflection causes error

This is the piece of code in Early Binding and works as expected.
---------------------------------------------------------------------------
using
ControlLicenseS ervice LicenseInfoClie nt lic =new ControlLicenseS ervice
LicenseInfoClie nt();
lic.Initialize( "sk26901CODA904 O",10300);
if (lic.IsSuccess )
{
MessageBox.Show ("Success");
}
else
MessageBox.Show ("Failure");

This is my code in Late binding:
------------------------------------

Assembly asm = null;
Type PublishType = null;
try
{
string strPath = GetInstalledPat h();
asm = Assembly.LoadFr om ("c:\\somefile. dll");
PublishType = asm.GetType("Co ntrolLicenseSer vice.LicenseInf oClient");
Object theObj = Activator.Creat eInstance(Publi shType);
// Array with Two members for passing the Parameter for Initialize method.
Type[] paramTypes = new Type[2];
paramTypes[0]= Type.GetType("S ystem.String");
paramTypes[1]= Type.GetType("S ystem.Int32");

// Get method info for Initialize( )
MethodInfo InitializeInfo =
PublishType.Get Method("Initial ize",paramTypes );
// Fill the array with the actual parameters
Object[] parameters = new Object[2];
parameters[0] = "sk26901CODA904 O";
parameters[1] = 10300;
InitializeInfo. Invoke(theObj,p arameters);
PropertyInfo pi = PublishType.Get Property("IsSuc cess");
string valu = pi.GetValue(the Obj,null).ToStr ing();
MessageBox.Show (valu);

}

I donot know what is going wrong here, but the code fails. Any one can
comment on this?
Does Reflection have any limitations? The initialize method may call
subroutines further and I feel that using late binding causes error in
calling the sub-subroutines.
Nov 16 '05 #1
3 1252
Venkat <Ve****@discuss ions.microsoft. com> wrote:
This is the piece of code in Early Binding and works as expected.
<snip>
I donot know what is going wrong here, but the code fails. Any one can
comment on this?


Not without a bit more information than "the code fails". Where does it
fail, and in what manner?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hmm..No problem...

I have posted the code fully in the first
thread. The only missing in that will be the dll file which is being
referenced.

As I had mentioned that the code correctly works in the early binding, I get
expected values. Running thru Reflection doesnot get the expected values. It
returrns the default values.

There is a method here called initialize which takes two parameters in and I
donot know internally how many methods it internally invokes, since I do have
just the dll file with me.

What I noticed from the log file that gets usually created when calling the
initialize method was that the internal call which is made from initioalize
method has failed. ie., initialize method calls another sub-routine where it
has failed, but this works correctly in early binding.

Hope this helps.
"Jon Skeet [C# MVP]" wrote:
Venkat <Ve****@discuss ions.microsoft. com> wrote:
This is the piece of code in Early Binding and works as expected.


<snip>
I donot know what is going wrong here, but the code fails. Any one can
comment on this?


Not without a bit more information than "the code fails". Where does it
fail, and in what manner?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Venkat <Ve****@discuss ions.microsoft. com> wrote:
Hmm..No problem...

I have posted the code fully in the first
thread.
No you didn't. You posted some code starting with a variable
declaration. Please read the page I referenced.
The only missing in that will be the dll file which is being
referenced.
Well, that doesn't really help us much, unfortunately.
As I had mentioned that the code correctly works in the early binding, I get
expected values. Running thru Reflection doesnot get the expected values. It
returrns the default values.

There is a method here called initialize which takes two parameters in and I
donot know internally how many methods it internally invokes, since I do have
just the dll file with me.

What I noticed from the log file that gets usually created when calling the
initialize method was that the internal call which is made from initioalize
method has failed. ie., initialize method calls another sub-routine where it
has failed, but this works correctly in early binding.


So, it sounds like the reflection part is working fine. I suggest you
find out from wherever you got the DLL from what the problem is likely
to be with initialization - it sounds like they should get a fair
amount of information from the logs. It could well just be a problem of
relying on another DLL being in the same directory, or something like
that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2218
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use reflection. The code I supplied is based on the SqlDataAdapter with reflection. The error occurs when trying to create the delegate that will be passed in to EventInfo.AddEventHandler. I get the following error: An unhandled exception of type...
1
2628
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am experimenting a bit with what I need to do this and have the following code snippet. But first if I pass the assembly name and type to Activator.CreateInstance() it always fails. However if I walk my assembly and get a type value, the call to...
1
3043
by: mark | last post by:
hi, I get the problem here, I have exception thrown when I try to cast the reflection created object. first there is BaseObject dll that implemation a interface, factory dll use the reflection load the dll, create the object and return. BaseObject reference the factory dll. factory.dll public object CreateObj(string objectType, ref string suppMsg) { string LoadObj = string.Format("WitsmlObjects.{0}",objectType);
5
2315
by: Wiktor Zychla | last post by:
Hello, I still have some problems with custom attributes and I ask someone for a helpful hand. In the appendix is the trivial ILAsm code with single custom attribute. The code compiles OK but then I cannot use reflection to load the assembly to read custom attributes because following code surprisingly fails in (*) line:
10
1909
by: Chris Morse | last post by:
Hi, I'm trying to figure out how to dynamically load an assembly and get an IClientPlugin interface to a class. I can get an "Object" reference to it after doing an "Activator.CreateInstance" call, but is there any way to get an IClientPlugin reference to it? Trying to do a "CType(obj, IClientPlugin)" throws an exception. Here's the code that loads the assembly and calls a method called
5
2194
by: Skandy | last post by:
Hello All: My second post in as many days! I'm trying to get this working. I have a form and a user control and trying to add the user control to this form. Without reflection this would be achieved as Form.Controls.Add(objUserControl); Now in my code I have the following:
7
2690
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
5
4304
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create delegate: public class DelegateEx {
0
1705
by: Gustavo Arriola | last post by:
Hola a todos! Estoy intentando ejecutar un método usando Reflection. El código es el siguiente: public static void SoapHandler(Exception Error) { try { Type assemblyType;
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7603
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.