473,383 Members | 1,984 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,383 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 3209
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.