无法在新的appdomain中加载C模块 [英] Failed to load C module in new appdomain

查看:86
本文介绍了无法在新的appdomain中加载C模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些.NET代码需要在单独的AppDomain中运行,除非调用COM组件,否则一切运行正常.
为了清楚起见,我编写了一个非常简单的repro,如下所示:

AppDomain ap = AppDomain.CreateDomain("newap");
ap.DoCallBack(
    () =>
    {
        //GroupPolicyObject is from assembly microsoft.grouppolicy.management.interop.dll
        GroupPolicyObject newGPO = new GroupPolicyObject();
    });

例外:

System.TypeInitializationException:类型的初始化程序 ''抛出了一个例外. ---> .ModuleLoadException:C ++模块失败 在尝试初始化默认appdomain时加载. ---> System.Runtime.InteropServices.COMException:无效的操作. (HRESULT的异常:0x80131022)在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo),网址为 .GetDefaultDomain()位于 .DoCallBackInDefaultDomain(IntPtr函数, 无效* Cookie) .LanguageSupport._Initialize(LanguageSupport * ) 在 .LanguageSupport.Initialize(LanguageSupport * )---内部异常堆栈跟踪的结尾--- .ThrowModuleLoadException(字符串 errorMessage,Exception innerException)位于 .LanguageSupport.Initialize(LanguageSupport * )在.cctor()

该代码可以在默认域中传递,并且不应是与.NET Framework版本有关的问题.

我在互联网上进行了大量搜索,但是没有有用的解决方案.有人知道什么是问题以及如何解决这个问题吗?

解决方案

最后我通过添加

对其进行了修复.

  <startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>

cofig文件中的

.

链接非常有用./p>

I have some .NET code that need to run in a separate AppDomain, and everything goes well except when there is call of COM component.
To make it clear, I wrote a very simple repro as below:

AppDomain ap = AppDomain.CreateDomain("newap");
ap.DoCallBack(
    () =>
    {
        //GroupPolicyObject is from assembly microsoft.grouppolicy.management.interop.dll
        GroupPolicyObject newGPO = new GroupPolicyObject();
    });

The exception:

System.TypeInitializationException: The type initializer for '' threw an exception. ---> .ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain. ---> System.Runtime.InteropServices.COMException: Invalid operation. (Exception from HRESULT: 0x80131022) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at .GetDefaultDomain() at .DoCallBackInDefaultDomain(IntPtr function, Void* cookie) at .LanguageSupport._Initialize(LanguageSupport* ) at .LanguageSupport.Initialize(LanguageSupport* ) --- End of inner exception stack trace --- at .ThrowModuleLoadException(String errorMessage, Exception innerException) at .LanguageSupport.Initialize(LanguageSupport* ) at .cctor()

The code can pass in default domain, and should not be the issue related with the version of .NET framework.

I did a lot of searching in the internet, but there’s no useful solution. Does anyone have ideas what’s the issue and how to achieve this?

解决方案

At last I fixed it by adding

  <startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>

in the cofig file.

The link is quite useful.

这篇关于无法在新的appdomain中加载C模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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