Azure Cache
-
lunedì 16 aprile 2012 20:45
I created an Integer variable in Cache. When i do a Put i get the folowing error:
System.NullReferenceException occurred
Message=Object reference not set to an instance of an object.
Source=Microsoft.ApplicationServer.Caching.Client
StackTrace:
at Microsoft.ApplicationServer.Caching.SimpleClient.SendMsgAndWait(RequestBody reqMsg, IRequestTracker& tracker)
at Microsoft.ApplicationServer.Caching.DataCache.SendReceive(RequestBody reqMsg, IMonitoringListener listener)
at Microsoft.ApplicationServer.Caching.DataCache.ExecuteAPI(RequestBody reqMsg, IMonitoringListener listener)
at Microsoft.ApplicationServer.Caching.DataCache.InternalPut(String key, Object value, DataCacheItemVersion oldVersion, TimeSpan timeout, DataCacheTag[] tags, String region, IMonitoringListener listener)
at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass19.<Put>b__18()
at Microsoft.ApplicationServer.Caching.MonitoringListenerFactory.EmptyListener.Microsoft.ApplicationServer.Caching.IMonitoringListener.Listen[TResult](Func`1 innerDelegate)
at Microsoft.ApplicationServer.Caching.DataCache.Put(String key, Object value)
at globalhealthportal.registerpatientgrid.savepatientrec_Click(Object sender, EventArgs e) in I:\inetpub\wwwroot\globalhealthportal\registerpatientgrid.vb:line 958
InnerException:Here is the way I defined the variable and then accessed it:
First I loaded it to the cache as follows:
Public famhistorycreated As Integer = 0 'familyhistory
defaultCache.Put("famhistorycreated", famhistorycreated)
In my program i then tried to change the value to 1.
Dim cacheFactory As New DataCacheFactory()
Dim defaultCache As DataCache = cacheFactory.GetDefaultCache()
defaultCache.Put("famhistorycreated", 1)thats when I get the error.
Tutte le risposte
-
martedì 17 aprile 2012 10:05Moderatore
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
- Contrassegnato come risposta Arwind - MSFTModerator lunedì 23 aprile 2012 06:08

