Our application is caching Entity Framework objects, so that our load-balanced sites can share cached items, instead of server A and B potentially displaying different content (using in-memory cache).
However, after we have done a deployment, we cannot retrieve the object from cache. The following error is thrown:
The deserializer cannot load the type to deserialize because type 'System.Data.Entity.DynamicProxies.Banner_FDE1BA817D206A7F0FED7955D1DAA7B97FEEF3213D26B91515A9AC18E73619EC' could not be found in assembly 'EntityFrameworkDynamicProxies-MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.
From what I gather, we have cached the EF-proxied version of the old DLL to AppFabric, and now retrieving this object is tripping EF over because it does not understand its type in the context of our new DLLs. We've done a few migrations between these 2 deployments, so effectively the DB model has changed.
How can I work around this? I think I'll have to remove the cached objects from AppFabric and re-add them in - but then we may hit the same problem the next release that we push out.
It is never a good idea to send heavy objects (such as the proxy types generated by EF) to a cache server. You should consider having small, lightweight DTO objects to communicate with the cache server.
Depending on the complexity of your types, you might even re-use the same entity types; however not the instances you get from EF but rather copy them to separate instances which will not be proxy types. Consider using e.g. EmitMappers to do the job of copying objects before sending them to the cache server.