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

查看:1020
本文介绍了无法使用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天全站免登陆