Hello,
I've reproduced your code at my side, and it's works fine. You exception is NullReferenceException, would you like to check your application context to see if there's some null value cause this exception?
My config file:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<configSections>
<section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core"
allowLocation="true" allowDefinition="Everywhere"/>
</configSections>
<appSettings>
<!--<add key="CacheService.Provider" value="InMemory" />-->
<add key="CacheService.Provider" value="Azure" />
</appSettings>
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/Models.Northwind.csdl|res://*/Models.Northwind.ssdl|res://*/Models.Northwind.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:[YOUR-SQL-AZURE-SERVER-ADDRESS];Initial Catalog=Northwind2;Integrated Security=False;User ID=[SQL-AZURE-USERNAME];Password=[SQL-AZURE-PASSWORD];MultipleActiveResultSets=False"" providerName="System.Data.EntityClient" />
</connectionStrings>
<dataCacheClients>
<dataCacheClient name="default">
<hosts>
<host name="<your cache service name space>" cachePort="22233" />
</hosts>
<securityProperties mode="Message">
<messageSecurity
authorizationInfo="<your cache service token>"
</messageSecurity>
</securityProperties>
</dataCacheClient>
</dataCacheClients>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<sessionState mode="Custom" customProvider="AzureCacheSessionStoreProvider">
<providers>
<add name="AzureCacheSessionStoreProvider"
type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
cacheName="default"
useBlobMode="true"
dataCacheClientName="default" />
</providers>
</sessionState>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Helpers" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
My code in HomeController.cs
DataCacheFactory factory = new DataCacheFactory();
DataCache defaultCache = factory.GetDefaultCache();
defaultCache.Put("famhistorycreated", 1);
object o = defaultCache["famhistorycreated"];
Hope this helps.
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact
msdnmg@microsoft.com
Microsoft One Code Framework