2013-05-15 16 views
6

Windows Azureキャッシュを使用してMVC4アプリケーションにセッションを格納しようとしています。私はLinkの手順に従ってアプリケーションを構築しますが、以下のコード行を使用してDataCacheのオブジェクトを作成しようとすると、'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment'の型初期化器が例外をスローしました

DataCache cache = new DataCache("default"); 

エラーが発生します。

が見つからないMicrosoft.WindowsAzure.ServiceRuntime.dllまたはバージョン が一致し、私は2.0.0に私のWindows Azureのエミュレータのバージョンを更新し、 がWindowsAzure.Cachingパッケージのバージョン2.0をインストールします.0.0 NuGet パッケージインストーラを使用します。今度はエラーが「 '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) 
+1

を参照するようにweb.configファイルとはapp.configエントリを更新する必要がありました。また

のInnerExceptionを含む*フル*例外を投稿してください。 –

+0

例外:呼び出しの対象によって例外がスローされました。 内部例外:{'' Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment 'の型初期化子が例外をスローしました。} – user2384784

+0

実際には* * *以上の情報はありませんか?スタックトレースはありませんか? –

答えて

1

私は同じ問題がありました。解決策は、すべてのプロジェクトで参照されているすべてのAzureアセンブリを同じソースにポイントすることでした(SDKフォルダ内のdll)。 NuGetManagerは、dllをpackagesのメインプロジェクトパスにコピーし、これらのdllへの参照を指します。私はApp.configファイルにこれを追加することで、同様の問題を解決してきました

1

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

私は信じて、これは、ServiceRuntime.dll(またはその依存関係の1つ)は、「混合モード」でありますアセンブリ。どのようなことを意味し、上記設定ラインについてもう少し情報が、ここで見つけることができます: What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config?

2

SDK 2.4へのAzure SDK 2.3からを移行するとき、私はこれを経験しました。

私は、移行が自動的すなわち

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 

任意のアセンブリこのアセンブリを参照していたロールは更新されなかったため、手動で行う必要がありました。私は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> 
+0

をご覧ください。マイグレーションはしませんでしたが、この問題は紺碧の雲で2.3バージョンになりました。ローカルマシンのエミュレータで正常に動作しています。 – AKS

関連する問題