{"id":26,"date":"2012-12-11T14:34:32","date_gmt":"2012-12-11T14:34:32","guid":{"rendered":"http:\/\/gkokot.com\/?p=26"},"modified":"2022-02-03T18:09:56","modified_gmt":"2022-02-03T18:09:56","slug":"exception-of-type-serialization-invaliddatacontractexception","status":"publish","type":"post","link":"https:\/\/gkokot.com\/?p=26","title":{"rendered":"Exception of type &#8216;Serialization.InvalidDataContractException&#8217;"},"content":{"rendered":"<p><a href=\"https:\/\/gkokot.com\/wp-content\/uploads\/2015\/01\/windows-phone-logo50.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-28\" src=\"https:\/\/gkokot.com\/wp-content\/uploads\/2015\/01\/windows-phone-logo50.png\" alt=\"windows-phone-logo50\" width=\"48\" height=\"48\"><\/a>&nbsp;<strong>During execution of your application, you receive following message:<\/strong><\/p>\n<p><em>A first chance exception of type &#8216;System.Runtime.Serialization.InvalidDataContractException&#8217; occurred in System.Runtime.Serialization.ni.dll<br \/>\nAn exception of type &#8216;System.Runtime.Serialization.InvalidDataContractException&#8217; occurred in System.Runtime.Serialization.ni.dll and wasn&#8217;t handled before a managed\/native boundary<\/em><\/p>\n<p>In my application (for Windows Phone), I created a new class (c#) &#8220;<em>TaskPlus.Models.Appoint<\/em>&#8221; and this class was origine of this issue.<\/p>\n<p><a href=\"https:\/\/gkokot.com\/wp-content\/uploads\/2015\/01\/GregBlogSerialization.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-27\" src=\"https:\/\/gkokot.com\/wp-content\/uploads\/2015\/01\/GregBlogSerialization-247x300.png\" alt=\"GregBlogSerialization\" width=\"247\" height=\"300\" srcset=\"https:\/\/gkokot.com\/wp-content\/uploads\/2015\/01\/GregBlogSerialization-247x300.png 247w, https:\/\/gkokot.com\/wp-content\/uploads\/2015\/01\/GregBlogSerialization.png 264w\" sizes=\"(max-width: 247px) 100vw, 247px\" \/><\/a><\/p>\n<p>Detailed error message :<\/p>\n<p><em>Type &#8216;TaskPlus.Models.Appoint&#8217; cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor &#8211; all public members of the type will then be serialized, and no attributes will be required.<\/em><\/p>\n<p>To solve problem, I created only &#8220;parameterless constructor&#8221;.<\/p>\n<p>It was easy &#8230;;-(<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;During execution of your application, you receive following message: A first chance exception of type<a class=\"readmore btn btn-info\" href=\"https:\/\/gkokot.com\/?p=26\" rel=\"nofollow\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":50,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-26","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/gkokot.com\/index.php?rest_route=\/wp\/v2\/posts\/26"}],"collection":[{"href":"https:\/\/gkokot.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gkokot.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gkokot.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gkokot.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26"}],"version-history":[{"count":3,"href":"https:\/\/gkokot.com\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":190,"href":"https:\/\/gkokot.com\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions\/190"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gkokot.com\/index.php?rest_route=\/wp\/v2\/media\/50"}],"wp:attachment":[{"href":"https:\/\/gkokot.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gkokot.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gkokot.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}