Membru care solicită informaţii
I am using the releast version of AppFabric (as of 20 Oct 2010) against an Entity Framework 4 Code-First data model. As part of this, we are drawing items from SQL into POCO objects and storing those objects in AppFabric. We can store/retrieve items with no problems.
When I recompile the code and try to retrieve an item (which I know is still in the cache), I get the following exception:
"The deserializer cannot load the type to deserialize because type 'System.Data.Entity.DynamicProxies.ACMEVersionHisto_0274F07D5CB3ECB757E0533C2AD895AD967B6E8D00FAB202E813E9C48E9493A5' could not be found in assembly 'EntityFrameworkDynamicProxies-ACME.Contracts, Version=188.8.131.52, 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."
I believe that the dynamic proxy classes used by EF4 to support the POCO model are recompiled with different signatures which are not backwards compatible with those items still stored in the cache - even though the structure of the class remains unchanged (ie same properties/fields/etc). Makes sense I guess, but it makes these latest two MS technologies completely incompatible, which I find hard to believe.
Of note, we used to use the HttpRuntime.Cache for our caching requirements, and never had any problems.
Any help, much appreciated - thanks.
I found a solution to this by disabling proxy creation using the ProxyCreationEnabled property on the db context configuration object. I am using EF 4.1.
This does however disable change tracking and removes support for lazy loading, neither of which I needed.
- Propus ca răspuns de TheNothingness 11 mai 2011 14:56
I too facing the same like issue. I am using EF 4.1 and inmplementing DbContext class, and creating the object collection by overriding the OnModelCreating(). This works for most of the entities but fails with one having large no of records in DB table.
I am able to get data from DB and managed to put the entity objects in AppServerFabric cache, but getting the mentioned error when I read them back from Cache.
I don't know where to put the code for suggested context.ContextOptions.ProxyCreationEnabled = false;
Can you please guide me?
I don't want to remove Virtual properties, as they are there to load dependent objects.
If I read the data from DB, creates objects using EF, Load them into AppFabricCache, Read again from Cache in a single step it works fine.
But if another process tries to read objects from existing AppFabric cache, the mentioned error comes in.
Should I implement it an any other ways? Suggetions are welcome.
To ensure that the Proxy Creation is always disabled you may want to put it into the constructor in your class that derives from DbContext. If you used the ADO.NET DbContext generator template to auto-generate the POCO classes and the DbContext classes you can modify the Context.tt that it generated so it will generate the context.ContextOptions.ProxyCreationEnabled = false; in the constuctor. Since Lazy Loading will not work without Dynamic Proxies you might as well turn them both off together. Find the WriteLazyLoadingEnabled method in the context.tt; below this.Configuration.LazyLoadingEnabled = false; add the line this.Configuration.ProxyCreationEnabled = false;
One other thing: in the EDMX designer set the Lazy Loading Enabled property to false as the above code checks that value.
- Propus ca răspuns de VIPG 17 aprilie 2012 11:54