473,399 Members | 3,038 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,399 software developers and data experts.

Activator.CreateInstanceFrom problem

Hi,

I have 2 dlls on which i have the same class MyClass defined. Say A.dll and
B.dll

The classes have a function (but different functionality)
void f();

I use .Net late binding using Activator.CreateInstanceFrom method to
dynamically call the method f() in either dll.

But I see that once i successfully call the f() method of either of the dll,
I am not able to call the f() method in the other dll even if
I pass the other dll's name as the parameter to CreateInstanceFrom method.
Always f() from the dll which got executed first is always getting
executed...

Am i missing something?

Raj
Nov 16 '05 #1
4 3211
CKR Rajesh <_r************@usa.net> wrote:
I have 2 dlls on which i have the same class MyClass defined. Say A.dll and
B.dll

The classes have a function (but different functionality)
void f();

I use .Net late binding using Activator.CreateInstanceFrom method to
dynamically call the method f() in either dll.

But I see that once i successfully call the f() method of either of the dll,
I am not able to call the f() method in the other dll even if
I pass the other dll's name as the parameter to CreateInstanceFrom method.
Always f() from the dll which got executed first is always getting
executed...

Am i missing something?


Rather than passing the other DLL's name, try using Assembly.GetType on
the appropriate loaded assembly, and then creating an instance using
Activator.CreateInstance passing in the actual type.

--
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
Yes, that was what i did earlier... same results!

Note that types with exact same name exist on both the assemblies. But I
wonder why that creates a prob....

-Raj

--
Try it for free:
http://www.sharpVoice.com
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
CKR Rajesh <_r************@usa.net> wrote:
I have 2 dlls on which i have the same class MyClass defined. Say A.dll and B.dll

The classes have a function (but different functionality)
void f();

I use .Net late binding using Activator.CreateInstanceFrom method to
dynamically call the method f() in either dll.

But I see that once i successfully call the f() method of either of the dll, I am not able to call the f() method in the other dll even if
I pass the other dll's name as the parameter to CreateInstanceFrom method. Always f() from the dll which got executed first is always getting
executed...

Am i missing something?


Rather than passing the other DLL's name, try using Assembly.GetType on
the appropriate loaded assembly, and then creating an instance using
Activator.CreateInstance passing in the actual type.

--
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
this is the code strip
Assembly m_oAssembly = Assembly.LoadFrom(assemblySource);
Type m_oTypeClass = m_oAssembly.GetType(classname,false);

MethodInfo m_oMethodInfoRequestInitialize =
m_oTypeClass.GetMethod("Initialize",System.Reflect ion.BindingFlags.Public
|System.Reflection.BindingFlags.Instance);

object m_oClassInstance = Activator.CreateInstance(m_oTypeClass);
m_oMethodInfoRequestInitialize.Invoke(m_oClassInst ance,m_oRequestArguments);

Thanks in advance

Raj
--
Try it for free:
http://www.sharpVoice.com
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
CKR Rajesh <_r************@usa.net> wrote:
I have 2 dlls on which i have the same class MyClass defined. Say A.dll and B.dll

The classes have a function (but different functionality)
void f();

I use .Net late binding using Activator.CreateInstanceFrom method to
dynamically call the method f() in either dll.

But I see that once i successfully call the f() method of either of the dll, I am not able to call the f() method in the other dll even if
I pass the other dll's name as the parameter to CreateInstanceFrom method. Always f() from the dll which got executed first is always getting
executed...

Am i missing something?


Rather than passing the other DLL's name, try using Assembly.GetType on
the appropriate loaded assembly, and then creating an instance using
Activator.CreateInstance passing in the actual type.

--
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
CKR Rajesh <_r************@usa.net> wrote:
Yes, that was what i did earlier... same results!

Note that types with exact same name exist on both the assemblies. But I
wonder why that creates a prob....


Could you post a short but complete example which we can use to
reproduce the problem?

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

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

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

Similar topics

26
by: CKR Rajesh | last post by:
Hi, I have 2 dlls on which i have the same class MyClass defined. Say A.dll and B.dll The classes have a function (but different functionality) void f(); I use .Net late binding using...
3
by: Wayne | last post by:
If I wanted to create an instance of a System.Windows.Forms.Button how would I go about doing this? I know if I specify the path to the DLL as the first param, and the qualified name as the second...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.