software you can take with you

Peter Foot

Microsoft Windows Phone Development MVP

DataContractSerializer and Internal types

Under Silverlight only public types may be serialized with the DataContractSerializer. If you want to make your data classes internal to your assembly and serialise them for use in a WCF service you will find that the service call will fail at runtime with a SecurityException inside a misleading exception about inability to communicate with the service. There is a workaround however which involves exposing your internal types to the Silverlight base class libraries with the InternalsVisibleTo attribute. Simply add the following code to your AssemblyInfo.cs file:-

  1. [assembly: InternalsVisibleTo("System.Runtime.Serialization, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab")]

If you use the DataContractJsonSerializer you must also add the System.Servicemodel.Web assembly (the public key is the same).

Published Aug 23 2010, 06:21 AM by PeterFoot
Filed under: ,

Comments

No Comments

About PeterFoot

Peter Foot is co-author of the Microsoft Mobile Development Handbook published by Microsoft Press. Peter has been awarded the Microsoft Most Valuable Professional (MVP) accolade since 2003 for his involvement in the Microsoft .NET Compact Framework developer community. Alongside an active presence in several online forums and communities, attendance at developer conferences and involvement in shared-source projects, Peter has also written a number of technical articles and maintains an active technical blog.
Copyright © 2001-2013 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting