Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

c# - JSON .Net Windows Mobile Error when serializing

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.NETSDKCompactFrameworkv3.5WindowsCENETCFv35.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...