gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:45:17 30 4
gpt4 key购买 nike

我正在尝试使用 Windows Azure 缓存在 MVC4 应用程序中存储 session 。我按照 Link 中的步骤构建了一个应用程序但是当我尝试使用下面的代码行创建 DataCache 的对象时。

DataCache cache = new DataCache("default");

发生错误:

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."

我正在使用 Windows 8 with VS2012 和 Windows Azure Emulator version 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)

最佳答案

我在从 Azure SDK 2.3 迁移到 SDK 2.4 时遇到过这种情况。

我注意到迁移自动修复了对我的网络和辅助角色的服务运行时的所有引用,即

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.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>

关于c# - 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 的类型初始值设定项抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560053/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com