473,387 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1233
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
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...
1
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...
1
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...
5
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...
10
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"...
5
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...
7
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...
5
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...
0
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.