Search code examples
cachingspring.net

Having trouble with Spring.NET caching


I have been reading this post to help me get going on my caching and am running into a problem. When I attempt to do a call to the method below I get the following error:

"Cannot initialize property or field node 'LocalTariffId' because the specified context is null."

I thought the attribute syntax I am using below would use the LocalTariffId property of the result once it returns to cache my data. This error occurs as soon as I attempt to step into the method. It seems to me that it is trying access that property too soon. I must be missing something so any advice you could provide is greatly appreciated!

[CacheResult("AspNetCache", "'LocalTariff.Id=' + LocalTariffId", TimeToLive = "00:10:00")]
public Domain.LocalTariffs.LocalTariff GetDefault(string agencyCode)

I am also getting a weird error after the first error I was hoping somebody could shed some light on. It has to do with log4net at least I think it does. My logging is working so I am not sure what this one is about.

IGCSoftware.HHG.Business.LocalTariffsFacade - Exception thrown in GetDefaultLocalTariff;GetDefaultLocalTariff;9c0bb393-369c-4501-a2ce-9325fe525e38;183341 ms
<log4net.Error>Exception rendering object type [Spring.Core.NullValueInNestedPathException]<stackTrace>System.BadImageFormatException: The parameters and the signature of the method don't match.
   at System.Reflection.RuntimeParameterInfo.GetParameters(IRuntimeMethodInfo methodHandle, MemberInfo member, Signature sig, ParameterInfo& returnParameter, Boolean fetchReturnParameter)
   at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
   at System.Reflection.RuntimeMethodInfo.GetParameters()
   at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Exception.GetStackTrace(Boolean needFileInfo)
   at System.Exception.ToString(Boolean needFileLineInfo)
   at System.Exception.ToString()
   at log4net.ObjectRenderer.DefaultRenderer.RenderObject(RendererMap rendererMap, Object obj, TextWriter writer)
   at log4net.ObjectRenderer.RendererMap.FindAndRender(Object obj, TextWriter writer)</stackTrace></log4net.Error>

Solution

  • You can't use the returned object to generate the key of the CacheResult attribute. You have to use parameters of the method to generate the key (here '#agencyCode').