Azure Cache Service - Failing to Serialize/Deserialize Classes marked with DataContract
-
2012年4月30日 14:55
We observed this strange behavior while deploying our MVC application as an Azure-hosted service. When we store objects in session that are tagged with DataContractAttribute they don't get serialized properly via the DistributedCacheSessionStateStoreProvider. Essentially, what we discovered is that you cannot use DataContract on items that you store in the Azure Cache. The Azure Cache store will not provide you with any errors either, you just end up with the default object type with default values during retrieval. Any values that should have been stored are missing, but the default object is retrieved.
While troubleshooting this problem, we did not see this problem in any of the other Session Store providers. We verified InProc, ASP.NET State Server, SQL Server Session, and AppFabric Cache all work perfectly with classes tagged with DataContract. However, it seems Azure Cache uses NetDataContractSerializer which provides some limitations on what types can be stored and retrieved via its cache store.
Will this be fixed in future Azure Cache version, and why is it not listed publicly as a limitation of the Azure Cache? This costs us 3 days of troubleshooting until we pinpointed the root cause. Hopefully others will benefit from this post.
- 編集済み SliverNinjas 2012年4月30日 14:56
- 種類を変更済み Arwind - MSFTModerator 2012年5月1日 2:40
すべての返信
-
2012年5月1日 2:40モデレータ
Hello,
Thanks for sharing.
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
-
2012年5月2日 16:17
There needs to be a clear note about this limitation in the MSDN documentation for Azure Cache.
To lift this restriction, should we add the idea to My Great Window Azure Idea?
-
2012年5月3日 1:44モデレータ
Hi,
Yes, I think documentation request may be more appropriate:
http://www.mygreatwindowsazureidea.com/forums/103403-windows-azure-documentation-voting
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
-
2012年6月13日 6:54
DistributedCacheSessionStateStoreProvider does support DataContract attribute on type and as far as i am aware other providers don't support it. They support [Serializable].
Since you are saying that you are getting default values, are you sure you have adde [DataMemmber] to instance memeber that you want to serialize. Until members are tagged with [DataMemmber], they don't get serialized, while in Serializable, all instance memmbers of the class marked with "Serializable" attributed are by default serialized.
You can read more about datacontract here:
http://msdn.microsoft.com/en-us/library/ms733127.aspx
MSFT

