Activator.CreateInstanceFrom问题 [英] Activator.CreateInstanceFrom problem
问题描述
我有两个dll,我有相同的MyClass类定义。说A.dll和
B.dll
这些类有一个功能(但功能不同)
void f() ;
我使用.net后期绑定使用Activator.CreateInstanceFrom方法来
动态调用dll中的方法f()。
但是我看到,一旦我成功调用了任何一个dll的f()方法,
我就无法调用其他dll中的f()方法,即使
我将其他dll的名称作为参数传递给CreateInstanceFrom方法。
始终f()来自首先执行的dll总是得到
执行...
我错过了什么吗?
Raj
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
推荐答案
CKR Rajesh< _r ************ @ usa.net>写道:
CKR Rajesh <_r************@usa.net> wrote:
我有2个dll,我有相同的类MyClass定义。说A.dll和
B.dll
这些类有一个功能(但功能不同)
void f();
我用。使用Activator.CreateInstanceFrom方法进行网后期绑定,以动态调用dll中的方法f()。
但是我看到,一旦我成功调用了任何一个dll的f()方法,
我无法在其他dll中调用f()方法,即使我将其他dll的名称作为参数传递给CreateInstanceFrom方法。
总是f()从首先执行的dll总是被执行......
我错过了什么?
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?
而不是传递另一个DLL的名称,尝试在
上使用Assembly.GetType适当加载的程序集,然后使用
Activator.CreateInstance传递实际类型来创建实例。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
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
是的,这就是我之前做过的......相同的结果!
请注意,两个程序集上都存在具有完全相同名称的类型。但是我想知道为什么会产生一个问题....
-Raj
-
免费试用:
http://www.sharpVoice.com
" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道
新闻:MP ************************ @ msnews.microsoft.c om ...
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>写道:
CKR Rajesh <_r************@usa.net> wrote:
我有2个dll,我有相同的类MyClass定义。说A.dll
和B.dll
这些类有一个功能(但功能不同)
void f();
我用。使用Activator.CreateInstanceFrom方法进行网后期绑定,以动态调用任一dll中的方法f()。
但是我看到,一旦我成功调用了任何一个$的f()方法b $ b dll,我无法在其他dll中调用f()方法,即使我将其他dll的名称作为参数传递给CreateInstanceFrom
方法。总是f()来自首先执行的dll总是被执行......
我错过了什么吗?
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?
而不是传递另一个DLL的名称,尝试在
适当加载的程序集上使用Assembly.GetType,然后使用
Activator.CreateInstance传递实际类型来创建实例。
- Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
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
>
这是代码条
汇编m_oAssembly = Assembly.LoadFrom(assemblySource);
键入m_oTypeClass = m_oAssembly.GetType(classname,false);
MethodInfo m_oMethodInfoRequestInitialize =
m_oTypeClass.GetMethod(" Initialize",System.Reflect ion.BindingFlags.Public
| System.Reflection。 BindingFlags.Instance);
对象m_oClassInstance = Activator.CreateInstance(m_oTypeClass);
m_oMethodInfoRequestInitialize.Invoke(m_oClassInst ance,m_oRequestArguments);
提前致谢
Raj
-
免费试用:
http://www.sharpVoice.com
" Jon Skeet [C#MVP] " < SK *** @ pobox.com>在消息中写道
新闻:MP ************************ @ msnews.microsoft.c om ...
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>写道:
CKR Rajesh <_r************@usa.net> wrote:
我有2个dll,我有相同的类MyClass定义。说A.dll
和B.dll
这些类有一个功能(但功能不同)
void f();
我用。使用Activator.CreateInstanceFrom方法进行网后期绑定,以动态调用任一dll中的方法f()。
但是我看到,一旦我成功调用了任何一个$的f()方法b $ b dll,我无法在其他dll中调用f()方法,即使我将其他dll的名称作为参数传递给CreateInstanceFrom
方法。总是f()来自首先执行的dll总是被执行......
我错过了什么吗?
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?
而不是传递另一个DLL的名称,尝试在
适当加载的程序集上使用Assembly.GetType,然后使用
Activator.CreateInstance传递实际类型来创建实例。
- Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
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
>
这篇关于Activator.CreateInstanceFrom问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!