在RoleEnvironment初始化程序中导致ModuleLoadException的原因是什么?

时间:2015-04-30 13:57:24

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

我正在使用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版本。

导致此异常的原因是什么,以及我如何修复它?

2 个答案:

答案 0 :(得分:1)

它看起来像是与应用域相关的新错误。我从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

答案 1 :(得分:1)

对于在Visual Studio Team Services(VSTS)中尝试执行测试任务时遇到此问题的任何其他人,请在构建中包含自定义设置文件,并在任务定义上设置路径位置。制作并设置ForcedLegacyMode attribute = 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