title: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception
body: <p>I am trying to use Windows Azure Caching to store sessions in a MVC4 application. I build a application following steps from <a href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/cache/" rel="nofollow">Link</a> but when i try to make object of DataCache using below code line.</p>
  
  <pre><code>DataCache cache = new DataCache("default");
  </code></pre>
  
  <p>Errors occurs: </p>
  
  <blockquote>
    <p>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."</p>
  </blockquote>
  
  <p>I am using <code>Windows 8 with VS2012 and Windows Azure Emulator version 2.0.0.</code></p>
  
  <p>I will grateful if anyone can help me on this.</p>
  
  <pre><code>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.&lt;&gt;c__DisplayClass15.&lt;InvokeActionMethodWithFilters&gt;b__12()
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  </code></pre>