What causes a ModuleLoadException in a RoleEnvironment initializer?

I am debugging a class library using the WCF service, which uses the installed Azure SDK 2.4 for Windows 8.1 using the WCF test client and the Visual Studio 2013 Ultimate debugger. The library was compiled using AnyCPU. An exception is thrown on a call RoleEnvironment.IsAvailable. Here are the details:

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

Enabling unmanaged code debugging did not give me new information. I tried installing the latest version of the Azure SDK by adding a flag useLegacyV2RuntimeActivationPolicy="true"to the configuration file, but none of this helped. The same library code that is being called from my test project works without exception. Using x86 and x64 test settings. Debug folders seem to contain the same version of the ServiceRuntime dll.

?

+4
3

, ( MS Connect)

Win10, VS2015. Fusion Log Viewer, , VS- - te.processhost.managed.exe. , 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 .

+5

, . RoleEnvironment MSTest, . :

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

, 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

+1

All Articles