C # Reflection GetType () exception

I have a strange mistake and don’t know why.

Type names passed to Assembly.GetType() must not specify an assembly. 

The strange thing: I do not use the GetType () method myself. This is caused by the following line:

 var domainCommunicator = (DomainCommunicator)dmn.CreateInstanceAndUnwrap(typeof(DomainCommunicator).FullName, "DomainCommunicator"); 

domainCommunicator inherits from MarshalByRefObject. This is publicly available, but when I change it to private, I get an exception that the assembly cannot be loaded. When I create an additional project in my solution and do not completely expose the .dll, nothing changes. Perhaps because I should have a link to the main project in my new AppDomain.

It is best to skip the DomainCommunicator class in reflection. It must be private and that. What exactly caused the exception?

+4
source share
1 answer

AppDomain.CreateAndUnwrap expects Assembly.FullName and Type.FullName :

 public Object CreateInstanceAndUnwrap( string assemblyName, string typeName ) 

Proper use:

 var type = typeof(DomainCommunicator); var domainCommunicator = (DomainCommunicator)dmn.CreateAndUnwrap(type.Assembly.FullName, type.FullName); 

Example values:

Assembly.FullName

  • AssemblyName, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

Type.FullName

  • Namespace+ClassName
+5
source

Source: https://habr.com/ru/post/1495528/


All Articles