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.
How is your application referencing the com dll? Is this also a .net dll? If it is being referenced as a project by your application and is also registered as a com dll, then there is a chance that your app is refering to two different copies of the dll in which case it will consider your Core classes to be two separate classes as they are in different dlls. You could consider hooking up the appdomains AssemblyLoad event to debug this and check the location of the assembly being loaded.