【问题标题】:What causes ModuleLoadException in RoleEnvironment initializer?是什么导致 RoleEnvironment 初始化程序中的 ModuleLoadException?
【发布时间】:2015-04-30 13:57:23
【问题描述】:

我正在使用 WCF 服务调试一个类库,该服务使用 WCF 测试客户端和 Visual Studio 2013 Ultimate 调试器在 Windows 8.1 上安装 Azure SDK 2.4。该库是使用 AnyCPU 编译的。调用RoleEnvironment.IsAvailable 时发生异常。以下是详细信息:

  Message=The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment'   threw an exception.
  ...
  InnerException: System.TypeInitializationException
       Message=The type initializer for '<Module>' threw an exception.
       Source=Microsoft.WindowsAzure.ServiceRuntime
       TypeName=<Module>
       StackTrace:
            at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment()
            at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor()
       InnerException: <CrtImplementationDetails>.ModuleLoadException
            HResult=-2146233088
            Message=The C++ module failed to load while attempting to initialize the default appdomain.
            Source=msshrtmi
            StackTrace:
                 at <CrtImplementationDetails>.ThrowModuleLoadException(String errorMessage, Exception innerException)
                 at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )
                 at .cctor()
            InnerException: System.Runtime.InteropServices.COMException
                 HResult=-2146234334
                 Message=Invalid operation. (Exception from HRESULT: 0x80131022)
                 Source=mscorlib
                 ErrorCode=-2146234334
                 StackTrace:
                      at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
                      at <CrtImplementationDetails>.GetDefaultDomain()
                      at <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie)
                      at <CrtImplementationDetails>.DefaultDomain.Initialize()
                      at <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* )
                      at <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* )
                      at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )

启用非托管代码调试没有给我任何新信息。我尝试安装 Azure SDK 的最新版本,将 useLegacyV2RuntimeActivationPolicy="true" 标志添加到配置文件,但这些都没有帮助。从我的测试项目中调用的相同库代码可以正常工作。同时使用 x86 和 x64 测试设置。调试文件夹似乎包含完全相同版本的 ServiceRuntime dll。

是什么导致了这个异常,我该如何解决?

【问题讨论】:

  • 你有没有找到解决这个问题的方法?在我们的 TeamCity 和 NUnit 测试运行程序的项目中遇到了这个问题。 MSTest 运行器都可以正常工作。
  • 我遇到了同样的错误,但是在普通的 Azure 应用服务中访问 RoleEnvironment 时 - 还没有找到任何解决方案 - 这让我发疯了......

标签: c# wcf visual-studio-2013 windows-8.1 azure-sdk-.net


【解决方案1】:

我找到了一个解决方法来解决我遇到的与您类似的问题(与 MS Connect 错误相同)

Win10、VS2015。使用 Fusion Log Viewer 我发现我的 VS 测试运行器是 te.processhost.managed.exe。按照找到 here 的类似说明,我将以下内容添加到 C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TE.processHost.managed.exe.config

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

重新启动 Visual Studio,测试开始工作。

【讨论】:

    【解决方案2】:

    它看起来像是一个与应用程序域相关的新错误。我从 MSTest 访问 RoleEnvironment 时看到了它,它使用应用程序域来隔离测试。这是堆栈跟踪:

    msshrtmi.dll!<Module>.<CrtImplementationDetails>.GetDefaultDomain() Unknown
    msshrtmi.dll!<Module>.<CrtImplementationDetails>.DoCallBackInDefaultDomain( function,  cookie)  Unknown
    msshrtmi.dll!<Module>.<CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(<CrtImplementationDetails>.LanguageSupport* value)  Unknown
    msshrtmi.dll!<Module>.<CrtImplementationDetails>.LanguageSupport._Initialize(<CrtImplementationDetails>.LanguageSupport* value) Unknown
    msshrtmi.dll!<Module>.<CrtImplementationDetails>.LanguageSupport.Initialize(<CrtImplementationDetails>.LanguageSupport* value)  Unknown
    msshrtmi.dll!<Module>.<Module>()    Unknown
    [Native to Managed Transition]  
    clrjit.dll!Compiler::impResolveToken(unsigned char const *,struct CORINFO_RESOLVED_TOKEN *,enum CorInfoTokenKind)   Unknown
    clrjit.dll!Compiler::impImportBlockCode(struct BasicBlock *)    Unknown
    clrjit.dll!Compiler::impImportBlock(struct BasicBlock *)    Unknown
    clrjit.dll!Compiler::impImport(struct BasicBlock *) Unknown
    clrjit.dll!Compiler::compCompile(void * *,unsigned long *,unsigned int) Unknown
    clrjit.dll!Compiler::compCompileHelper(struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,unsigned int,enum CorInfoInstantiationVerification)    Unknown
    clrjit.dll!Compiler::compCompile(struct CORINFO_METHOD_STRUCT_ *,struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,unsigned int)    Unknown
    clrjit.dll!jitNativeCode(struct CORINFO_METHOD_STRUCT_ *,struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,unsigned int,void *) Unknown
    clrjit.dll!CILJit::compileMethod(class ICorJitInfo *,struct CORINFO_METHOD_INFO *,unsigned int,unsigned char * *,unsigned long *)   Unknown
    [Managed to Native Transition]  
    clrjit.dll!Compiler::impResolveToken(unsigned char const *,struct CORINFO_RESOLVED_TOKEN *,enum CorInfoTokenKind)   Unknown
    clrjit.dll!Compiler::impImportBlockCode(struct BasicBlock *)    Unknown
    clrjit.dll!Compiler::impImportBlock(struct BasicBlock *)    Unknown
    clrjit.dll!Compiler::impImport(struct BasicBlock *) Unknown
    clrjit.dll!Compiler::compCompile(void * *,unsigned long *,unsigned int) Unknown
    clrjit.dll!Compiler::compCompileHelper(struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,unsigned int,enum CorInfoInstantiationVerification)    Unknown
    clrjit.dll!Compiler::compCompile(struct CORINFO_METHOD_STRUCT_ *,struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,unsigned int)    Unknown
    clrjit.dll!jitNativeCode(struct CORINFO_METHOD_STRUCT_ *,struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,unsigned int,void *) Unknown
    clrjit.dll!CILJit::compileMethod(class ICorJitInfo *,struct CORINFO_METHOD_INFO *,unsigned int,unsigned char * *,unsigned long *)   Unknown
    Microsoft.WindowsAzure.ServiceRuntime.dll!Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.RoleEnvironment()   Unknown
    

    【讨论】:

    • MS Connect 现在已关闭(也许它正在尝试将 RoleEnvironment 与应用程序域一起使用 :)。否则,我会提交一个错误。
    • 网站已备份(虽然超级笨拙 - 可能有很多人报告错误)。 Here's the bug report
    【解决方案3】:

    对于尝试在 Visual Studio Team Services (VSTS) 中执行测试任务时遇到此问题的其他人,请在构建中包含自定义设置文件并在任务定义中设置路径位置。制作并设置ForcedLegacyMode 属性= true。这为我解决了这个问题。

    <?xml version="1.0" encoding="utf-8"?>
    <RunSettings>
          <TargetFrameworkVersion>Framework45</TargetFrameworkVersion>  
      <MSTest>
         <ForcedLegacyMode>true</ForcedLegacyMode> 
      </MSTest>
    </RunSettings>
    

    有关 Visual Studio 测试文件的其他设置和属性的文档,请参阅 https://msdn.microsoft.com/library/jj635153.aspx?f=255&MSPPError=-2147217396

    在此处查看测试任务的 VSTS 任务文档enter link description here

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 2018-04-22
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多