的类型初始“Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment'引发了异常 [英] The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception
问题描述
我想使用Windows Azure的缓存来存储会话在MVC4应用。我建立了下面的链接步骤的应用但是当我尝试使用下面code线进行数据高速缓存的对象。
数据高速缓存缓存=新的数据高速缓存(默认);
发生错误:
Microsoft.WindowsAzure.ServiceRuntime.dll没有发现或版本 不匹配的,我更新了Windows Azure的模拟器版本为2.0.0,并 使用的NuGet安装WindowsAzure.Caching包版本2.0.0.0 包安装程序。现在错误更改为的类型初始 Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment'抛出 例外。
我使用 Windows 8中使用VS2012和Windows Azure的模拟器版本2.0.0。
我会感激,如果任何人都可以帮助我在此。
的InnerException
消息:类型初始值设定为Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment'引发了异常。
资料来源:Microsoft.WindowsAzure.ServiceRuntime
堆栈跟踪:在Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable()
在Microsoft.ApplicationServer.Caching.AzureClientHelper.RoleUtility.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(String clientConfigurationName)
在Microsoft.ApplicationServer.Caching.DataCache..ctor(字符串cacheName,字符串clientConfigurationName)
在Microsoft.ApplicationServer.Caching.DataCache..ctor(字符串cacheName)
在MvcWebRole.Controllers.HomeController.Index()在d:\潘卡\ Azure.Test \ Caching.Sample \ MvcWebRole \控制器\ HomeController.cs:行15
在lambda_method(封闭,ControllerBase,对象[])
在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__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter过滤器,ActionExecutingContext preContext,Func`1续)
我从Azure的SDK 2.3迁移以SDK 2.4 时,经历了这一点。
我注意到迁移自动固定在服务运行时都引用了我的web和辅助角色,即
C:\ Program Files文件\微软的SDK \ Windows Azure的\ .NET SDK \ V2.3 \文献\ Microsoft.WindowsAzure.ServiceRuntime.dll
更改为:
C:\ Program Files文件\微软的SDK \的Azure \ .NET SDK \ V2.4 \文献\ Microsoft.WindowsAzure.ServiceRuntime.dll
但是从引用的本次大会网络/辅助角色中引用的任何组件没有更新,所以我不得不做手工。
此外,我不得不更新的web.config和app.config中的条目引用2.4.0.0
&LT; dependentAssembly&GT;
&LT; assemblyIdentity名=Microsoft.WindowsAzure.ServiceRuntime公钥=31bf3856ad364e35文化=中性/&GT;
&LT; bindingRedirect oldVersion =0.0.0.0-2.4.0.0NEWVERSION =2.4.0.0/&GT;
&LT; / dependentAssembly&GT;
I am trying to use Windows Azure Caching to store sessions in a MVC4 application. I build a application following steps from Link but when i try to make object of DataCache using below code line.
DataCache cache = new DataCache("default");
Errors occurs:
Microsoft.WindowsAzure.ServiceRuntime.dll not found or version mismatched, I updated my Windows Azure Emulator version to 2.0.0 and install WindowsAzure.Caching package version 2.0.0.0 using NuGet package installer. Now the error changes to "The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception."
I am using Windows 8 with VS2012 and Windows Azure Emulator version 2.0.0.
I will grateful if anyone can help me on this.
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)
I experienced this when migrating from Azure SDK 2.3 to SDK 2.4.
I noticed the migration automatically fixed all references to the service runtime for my web and worker roles, i.e.
C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.3\ref\Microsoft.WindowsAzure.ServiceRuntime.dll
changed to:
C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.4\ref\Microsoft.WindowsAzure.ServiceRuntime.dll
However any assemblies referenced from the web/worker roles that referenced this assembly didn't update so I had to do it manually.
In addition I had to update the web.config and app.config entries to reference 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>
这篇关于的类型初始“Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment'引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!