JSON .Net Windows Mobile Error when serializing

丶灬走出姿态 提交于 2019-11-28 07:47:30

问题


I am running this bit of code:

 string serialized = JsonConvert.SerializeObject(somethingToSend);

And it throws this exception:

MissingMethodException: Could not load type 'System.Runtime.Serialization.StreamingContext' from assembly 'mscorlib, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC'.

Here is my configuration:

  • Visual Studio 2008 (with all the latest service packs etc)
  • Smart Device project targeting Windows Mobile 6 .Net 3.5
  • Json DotNet version 4.5 Release 7 (referencing the DLL from the WindowsPhone folder in the zip)

The answer to this question "Is there a library to read JSON in C# on Windows Mobile?" implies that it should work.

I am running it in debug with the real device attached (so no emulator) where I have previously installed the CAB file from here without error:

C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\NETCFv35.wce.armv4.cab

The application runs fine until I click the button that is running the line above, so does anyone know what I am missing?

This thread "Json.Compact.dll for Windows CE 5.0?" suggests that I would need the Windows SDK installed, which I have. Given it is running on the device itself I guess that is not going to be the fix anyway.

The other suggestion is to build from source but like the author of the question I cannot load the project file into VS 2008 to do that. I could create a new project and include the source files and try to get it to compile but before I do that I thought I would ask here if it is worth it or if there is something else missing from the installation on the device perhaps? Or maybe I should be using an alternate build?


回答1:


So I needed to RTFM! The readme file says:

Microsoft stopped support for the Compact Framework in Visual Studio 2010. For a Compact Framework 3.5 build download Json.NET 3.5.

So I grabbed the most recent 3.5 version which is: Json.NET 3.5 Release 8, updated my reference to point to the Newtonsoft.Json.Compact.dll assembly, ran it and it worked fine.



来源:https://stackoverflow.com/questions/11295872/json-net-windows-mobile-error-when-serializing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!