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

1

4

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);
Marcellus answered 10/5, 2012 at 13:20 Comment(1)
You can use new methods this way: evidence.AddAssemblyEvidence(new ApplicationDirectory(Assembly.GetExecutingAssembly().FullName)); evidence.AddHostEvidence(new Zone(SecurityZone.MyComputer));Headpiece
M
1

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.

Marcellus answered 10/5, 2012 at 23:37 Comment(1)
Marking the class with SerializableAttribute and deriving it from MarshalByRefObject is somewhat mutually exclusive when cross-appdomain calls are considered.Devondevona

© 2022 - 2024 — McMap. All rights reserved.