cominteropappdomainsystem.io.packaging

Unable to determine the identity of domain using System.IO.Packaging


I am getting "Unable to determine the identity of domain" when using System.IO.Packaging through COM Interop, there are a few articles describing why this is happening and the solution is to run the offending function in its own AppDomain.

So I took the sample code, which looks like the below but I still get the error, I am wondering what i am doing wrong and also, with VS 2010 it says AddAssembly and AddHost are obsolete - I wonder if that means they are no longer implemented, but if thats the case I dont really understand how to use the new methods (AddAssemblyEvidence and AddHostEvidence)??

 AppDomainSetup setup = new AppDomainSetup();
 setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;

 Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
 evidence.AddAssembly(Assembly.GetExecutingAssembly().FullName);
 evidence.AddHost(new Zone(SecurityZone.MyComputer));

 AppDomain domain = AppDomain.CreateDomain("BlobPackage", evidence, setup);

 BlobPackage blob_interal = (BlobPackage)domain.CreateInstanceAndUnwrap(typeof(BlobPackage).Assembly.FullName, typeof(BlobPackage).FullName);

 blob_interal.pack(FilePath, RootPath, m_source_files); <-- STILL FAILS

 AppDomain.Unload(domain);

Solution

  • I solved this one myself, I forgot to inherit my class from MarshalByRefObject.

    Its a bit stupid, it allows you to create an instance and call it except its still running in the default domain, you would think it would throw an exception or something, anyway by marking the class as [Serializable()] and deriving from MarshalByRefObject fixes it.