I'm getting this error when trying to get instanse of class in separated Application Domain. Here is code:
string assemblyName = Assembly.GetExecutingAssembly().FullName;
string typeName = "Namespace.ClassName";
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
SecurityZone zone = SecurityZone.MyComputer;
// Set up the Evidence
Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
Evidence evidence = new Evidence(baseEvidence);
evidence.AddAssembly(assemblyName);
evidence.AddHost(new Zone(zone));
AppDomain app = AppDomain.CreateDomain("Processor AppDomain", evidence, setup);
core = (Core)app.CreateInstanceAndUnwrap(assemblyName, typeName);
Both classes (calling and called) are in same assemby (COM dll).
So does anybody know what is the reason ot this exception? Thanks for any response.
typeNamerefers to theCoretype? What does the debugger show when you look at the result ofCreateInstanceAndUnwrap()without casting? - svicktypeNamerealy refers toCore, otherwise I'll get other exception of typeFileNotFoundExceptionorTypeLoadException. When I changed last string of this example toObject core = app.CreateInstanceAndUnwrap(assemblyName, typeName);and debugged it, everything was going right scenario - fields of Core class was initialized, constructor called and object was returned. But this returned object isSystem.Runtime.Remoting.Proxies.__TransparentProxyby type for calling class. and looks like I could not cast this object toCoretype. - ShelestCreateInstanceAndUnwrapmethod is on of them. You can see that I'm trying to do the same thing as posted on msdn.microsoft.com/en-us/library/3c4f1xde.aspx (see an Example). - ShelestSerializableor does your type inheritMarshalByRefObjecttype? - psulek