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

Leo*_*lev 4 c# wcf azure-sdk-.net visual-studio-2013 windows-8.1

我正在使用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* )
Run Code Online (Sandbox Code Playgroud)

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

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

Ste*_*eve 5

我发现了一个与我的问题类似的问题的解决方法(与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>
Run Code Online (Sandbox Code Playgroud)

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