无法使用 System.IO.Packaging 确定域的身份 [英] Unable to determine the identity of domain using System.IO.Packaging

查看:22
本文介绍了无法使用 System.IO.Packaging 确定域的身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过 COM Interop 使用 System.IO.Packaging 时收到无法确定域的身份",有几篇文章描述了为什么会发生这种情况,解决方案是在其自己的 AppDomain 中运行有问题的函数.

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.

所以我采用了如下所示的示例代码,但我仍然遇到错误,我想知道我做错了什么,而且,在 VS 2010 中,它说 AddAssembly 和 AddHost 已过时 - 我想知道这是否意味着它们不再实施,但如果是这样的话,我真的不明白如何使用新方法(AddAssemblyEvidence 和 AddHostEvidence)??

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);

推荐答案

我自己解决了这个问题,我忘记从 MarshalByRefObject 继承我的类了.

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

它有点愚蠢,它允许你创建一个实例并调用它,除非它仍然在默认域中运行,你会认为它会抛出异常或其他东西,无论如何通过将类标记为 [Serializable()] 和从 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.

这篇关于无法使用 System.IO.Packaging 确定域的身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆