我正在尝试使用 Windows Azure 缓存将会话存储在 MVC4 应用程序中。我按照Link的步骤构建了一个应用程序,但是当我尝试使用下面的代码行创建 DataCache 对象时。
DataCache cache = new DataCache("default");
发生错误:
Microsoft.WindowsAzure.ServiceRuntime.dll 未找到或版本不匹配,我将我的 Windows Azure 模拟器版本更新为 2.0.0 并使用 NuGet 包安装程序安装 WindowsAzure.Caching 包版本 2.0.0.0。现在错误更改为“'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 的类型初始化程序引发了异常。”
我在用Windows 8 with VS2012 and 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)