Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# '的类型初始值设定项;Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment';抛出异常_C#_.net_Azure Worker Roles_Azure Caching - Fatal编程技术网

C# '的类型初始值设定项;Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment';抛出异常

C# '的类型初始值设定项;Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment';抛出异常,c#,.net,azure-worker-roles,azure-caching,C#,.net,Azure Worker Roles,Azure Caching,我正在尝试使用Windows Azure缓存在MVC4应用程序中存储会话。我按照以下步骤构建应用程序,但当我尝试使用下面的代码行创建DataCache对象时 DataCache cache = new DataCache("default"); 出现以下错误: 找不到Microsoft.WindowsAzure.ServiceRuntime.dll或其版本 不匹配,我将我的Windows Azure Emulator版本更新为2.0.0和 使用NuGet安装WindowsAzure.Cachi

我正在尝试使用Windows Azure缓存在MVC4应用程序中存储会话。我按照以下步骤构建应用程序,但当我尝试使用下面的代码行创建DataCache对象时

DataCache cache = new DataCache("default");
出现以下错误:

找不到Microsoft.WindowsAzure.ServiceRuntime.dll或其版本 不匹配,我将我的Windows Azure Emulator版本更新为2.0.0和 使用NuGet安装WindowsAzure.Caching软件包版本2.0.0.0 软件包安装程序。现在,错误更改为“的类型初始值设定项” “Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment”引发错误 例外。”

我正在将Windows 8与VS2012和Windows Azure Emulator 2.0.0版一起使用。

如果有人能在这方面帮助我,我将不胜感激

InnerException
    Message: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception.

    Source: Microsoft.WindowsAzure.ServiceRuntime

    Stack Trace:    at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable()
       at Microsoft.ApplicationServer.Caching.AzureClientHelper.RoleUtility.IsAzureEnvironmentAvailable()

Stack Trace:    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration.Initialize(String clientName)
   at Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration..ctor()
   at Microsoft.ApplicationServer.Caching.DataCacheFactory..ctor()
   at Microsoft.ApplicationServer.Caching.DataCacheFactory.InitializeOrFetchSingletonFactoryInstance(String clientConfigurationName)
   at Microsoft.ApplicationServer.Caching.DataCache..ctor(String cacheName, String clientConfigurationName)
   at Microsoft.ApplicationServer.Caching.DataCache..ctor(String cacheName)
   at MvcWebRole.Controllers.HomeController.Index() in d:\Pankaj\Azure.Test\Caching.Sample\MvcWebRole\Controllers\HomeController.cs:line 15
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException
消息:“Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment”的类型初始值设定项引发异常。
来源:Microsoft.WindowsAzure.ServiceRuntime
堆栈跟踪:在Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable()上
位于Microsoft.ApplicationServer.Caching.AzureClientHelper.RoleUtibility.IsAzureEnvironmentAvailable()上
堆栈跟踪:位于System.RuntimeMethodHandle.InvokeMethod(对象目标、对象[]参数、签名符号、布尔构造函数)
位于System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(对象obj,对象[]参数,对象[]参数)
在System.Reflection.RuntimeMethodInfo.Invoke(对象obj、BindingFlags invokeAttr、绑定器绑定器、对象[]参数、CultureInfo区域性)
在System.Reflection.MethodBase.Invoke(对象obj,对象[]参数)处
位于Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration.Initialize(字符串clientName)
在Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration..ctor()上
在Microsoft.ApplicationServer.Caching.DataCacheFactory..ctor()上
在Microsoft.ApplicationServer.Caching.DataCacheFactory.InitializeOrFetchSingletonFactoryInstance(字符串clientConfigurationName)中
位于Microsoft.ApplicationServer.Caching.DataCache..ctor(字符串cacheName,字符串clientConfigurationName)
位于Microsoft.ApplicationServer.Caching.DataCache..ctor(字符串cacheName)
在d:\Pankaj\Azure.Test\Caching.Sample\MvcWebRole\Controllers\HomeController.cs中的MvcWebRole.Controllers.HomeController.Index()处:第15行
在lambda_方法中(闭包、控制器基、对象[])
位于System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)
位于System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)
在System.Web.Mvc.ControllerActionInvoker.c_uuDisplayClass15.b_uuu12()中
位于System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter筛选器、ActionExecutingContext预文本、Func`1 continuation)

我也有同样的问题。解决方案是将每个项目中所有引用的Azure程序集指向同一个源(对我来说是SDK文件夹中的DLL)。NuGetManager将DLL复制到包下的主项目路径中,并指向这些DLL的引用。

我通过将此添加到App.config解决了一个类似的问题:

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

这是因为,我相信ServiceRuntime.dll(或它的一个依赖项)是一个“混合模式”程序集。有关这意味着什么的更多信息,以及上面的配置行,可以在这里找到:

我从Azure SDK 2.3迁移到SDK 2.4时体验到了这一点

我注意到迁移自动修复了我的web和工作者角色对服务运行时的所有引用,即

C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.3\ref\Microsoft.WindowsAzure.ServiceRuntime.dll
改为:

C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.4\ref\Microsoft.WindowsAzure.ServiceRuntime.dll
但是,从引用此程序集的web/worker角色引用的任何程序集都没有更新,因此我必须手动执行此操作

此外,我还必须将web.config和app.config条目更新为参考2.4.0.0

<dependentAssembly>
    <assemblyIdentity name="Microsoft.WindowsAzure.ServiceRuntime" publicKeyToken="31bf3856ad364e35" culture="neutral" />
     <bindingRedirect oldVersion="0.0.0.0-2.4.0.0" newVersion="2.4.0.0" />
</dependentAssembly>


请发布完整异常,包括InnerException。异常:调用目标已引发异常。内部异常:{“Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment”的类型初始值设定项引发了异常。}真的没有更多的信息了吗?没有堆栈跟踪?请查找上面的异常详细信息。我没有迁移,但在azure cloud中使用2.3 verison解决了此问题。在本地机器模拟器上,它工作正常。