使用位于另一个AppDomain上的Dll中的对象 [英] Use an Object from Dll located on another AppDomain
问题描述
嗨
我在应用程序中创建了一个AppDomain,并将程序集动态加载到此appdomain.所有这些功能都可以正常工作,但是我无法使用这些dll中的对象.
我创建了一个名为Loader的类,该类继承自 MarshalByRefObject ,然后将程序集加载到该类.在我的默认应用程序域中,通过使用
使用这些类
Hi
I created one AppDomain in my application and dynamically load an assembly to this appdomain. All these functionalities are working fine but i can''t use an object from these dll.
I Created one class named Loader that inherits from MarshalByRefObject, load the assembly to this class. in my default appdomain use these class by using
loader = (Loader)domain.CreateInstanceAndUnwrap(typeof(Loader).Assembly.FullName, typeof(Loader).FullName);
我可以在新创建的appdomain中使用dll中的对象,但是当我将该对象分配给默认appdomain中的任何成员时,它会给出类似
I can use object from dll in newly created appdomain, but when i assign that object to any of my member inside my default appdomain then it gives the error like
Type ''WpfCustomControlLibrary1.Page1'' in assembly ''WpfCustomControlLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'' is not marked as serializable.
的错误
请给我解决这个问题的方法
在此先感谢
Naufal k K
Please give me a solution for this problem
Thanks in advance
Naufal k K
推荐答案
首先,请务必意识到,不同的应用程序域与进程之间是完全隔离的.也就是说,您可以使用IPC在它们之间交换数据和事件,就像在不同进程中一样.
现在,另外,类System.AppDomain
提供了一些特殊的轻量级IPC简化方法.也许我不会全部使用它们,而是我经常使用的那些,但它们也是最重要的:方法SetData
,GetData
和DoCallBack
;对于大多数目的而言,使用这三个就足够了.
有关更多详细信息,请参见 http://msdn.microsoft.com/en-us/library/system .appdomain.aspx [^ ].
—SA
First of all, do realize that different Application Domains are isolated from each other as thoroughly as processes. That said, you can exchange data and events between them using IPC, as in the case of different processes.
Now, additionally, the classSystem.AppDomain
provides some special light-weight simplified means of IPC. Perhaps I will name not all of them but those I often used, but they are also the most important ones: the methodsSetData
,GetData
andDoCallBack
; using of those three could be enough for majority of purposes.
For more detail, see http://msdn.microsoft.com/en-us/library/system.appdomain.aspx[^].
—SA
这篇关于使用位于另一个AppDomain上的Dll中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!