469,935 Members | 1,476 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

Reflection causes error

This is the piece of code in Early Binding and works as expected.
---------------------------------------------------------------------------
using
ControlLicenseService LicenseInfoClient lic =new ControlLicenseService
LicenseInfoClient();
lic.Initialize("sk26901CODA904O",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 = GetInstalledPath();
asm = Assembly.LoadFrom ("c:\\somefile.dll");
PublishType = asm.GetType("ControlLicenseService.LicenseInfoClie nt");
Object theObj = Activator.CreateInstance(PublishType);
// Array with Two members for passing the Parameter for Initialize method.
Type[] paramTypes = new Type[2];
paramTypes[0]= Type.GetType("System.String");
paramTypes[1]= Type.GetType("System.Int32");

// Get method info for Initialize( )
MethodInfo InitializeInfo =
PublishType.GetMethod("Initialize",paramTypes);
// Fill the array with the actual parameters
Object[] parameters = new Object[2];
parameters[0] = "sk26901CODA904O";
parameters[1] = 10300;
InitializeInfo.Invoke(theObj,parameters);
PropertyInfo pi = PublishType.GetProperty("IsSuccess");
string valu = pi.GetValue(theObj,null).ToString();
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 1136
Venkat <Ve****@discussions.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.com>
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****@discussions.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Venkat <Ve****@discussions.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Wiktor Zychla | last post: by
5 posts views Thread by Skandy | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
5 posts views Thread by Klaudiusz Bryja | last post: by
reply views Thread by Gustavo Arriola | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.