CreateInstanceAndUnwrap and Domain

后端 未结 1 829
无人共我
无人共我 2021-01-02 09:14

I have a property whose instance I want to be in other domain.

public ModuleLoader Loader
        {
            get
            {

                if(_loader         


        
相关标签:
1条回答
  • 2021-01-02 09:57

    If you want to actually run the code in the other assembly, you need to make your ModuleLoader class inherit from MarshalByRefObject. If you do that, CreateInstanceAndUnwrap() will actually return a proxy and the call will be executed in the other appdomain.

    If you don't do that, and instead mark the class as Serializable (as an exception message suggests), CreateInstanceAndUnwrap() will create the object in the other appdomain, serialize it, transfer the serialized form to the original appdomain, deserialize it there and call the method on the deserialized instance.

    0 讨论(0)
提交回复
热议问题