Version for .Net Compact Framework 2.0

Nov 4, 2009 at 7:57 AM
Edited Nov 4, 2009 at 7:57 AM

Hi james,

Is there a version for CF2?  Problem is a lot of devices don't get preinstalled with 3.5 and so by using Json.net, we will also require our users to install CF3.5, which is not ideal.

Thanks,

Ben

Nov 9, 2009 at 10:02 AM

Hi Ben,

I "patched" an earlier version (i think it was the rc before) of Json .NET to work with CF 2.0. By then Json .NET was not yet officially .NET 2.0 compatible (desktop version). It took me only a couple of hours to hack the sources, mostly adding some preprocessor definitions at hopefully the right places. I guess now that there is a 2.0-compatible version it should be even easier.

If you want to do it yourself I recommend to get the LinqBridge sources and compile them against CF 2.0 (that was only one small change i think), i got strange compile problems targeting the desktop binary of LinqBridge from my Json.NET CF-project.

If you don't want to do that and if James is ok with it i could send you my binaries of Json.NET and LinqBridge for CF 2.0 but you shouldn't expect support by either me or James if you encounter problems.

 

Regards,

Gunter

Jan 25, 2010 at 8:05 AM

Hi

version 3.5 release 6 is great but when I use it in my .NET compact framework 2.0 project, I get Missing method Reszie Array Size error!!

How do I resolve this?

 

Many thanks!

Peter

Jan 25, 2010 at 8:18 AM
Edited Jan 25, 2010 at 8:18 AM

Hi Peter,

I just "ported" 3.6r6 to CF 2.0 again. This time it was only creating a CF 2.0 project, adding all source files, adding NET20 to the preprocessor defines and replacing Environment.NewLine with "\r\n". I didn't get your error. Do you get it at compile time or run time? Please post the error message.

 

Regards,

Gunter

Jan 25, 2010 at 8:57 AM
Edited Jan 25, 2010 at 9:09 AM

I have an custom object called RequestResult

I tried to parse

RequestResult RequestResult = Newtonsoft.Json.JsonConvert.DeserializeObject<RequestResult>(jsontext);

Compiling has no problems.

But during runtime, when the above is called, I get an exception error:

"MissingMethodException was unhandled

Method not found: Resize Syste.Array"

 

I am using Visual Studio 2008, .NET Compact Framework 2.0 project

 

 

Jan 25, 2010 at 9:50 AM

You are right, Array.Resize is not implemented in CF 2.0. It is in 3.5.

I never understood why MS left out features like that in Compact Framework to save a couple of hundred bytes making otherwise trivial ports so much harder to do.

The CF 3.5 version of JSON has also unit tests based on nunitlite. I didn't yet figure out how to run these tests on the device emulator, otherwise the tests would probably have catched that error. But it seems i should try to run the test suite to catch errors like that.

I searched for a call of Array.Resize in the JSON sources but i couldn't find one. The question is where this call happens. Could you post the complete stack trace?

Anyway, Array.Resize is easy to implement, like this for example:

 

namespace System
{
    public static class ArrayEx
    {
        /// <exception cref="ArgumentOutOfRangeException"><c>newSize</c> is out of range.</exception>
        public static void Resize<T>(ref T[] array, int newSize)
        {
            if (newSize < 0)
            {
                throw new ArgumentOutOfRangeException("newSize");
            }
            T[] sourceArray = array;
            if (sourceArray == null)
            {
                array = new T[newSize];
            }
            else if (sourceArray.Length != newSize)
            {
                T[] destinationArray = new T[newSize];
                Array.Copy(sourceArray, 0, destinationArray, 0,
                    (sourceArray.Length > newSize) ? newSize : sourceArray.Length);
                array = destinationArray;
            }
        }
    }
}

Regards,

Gunter

 

 

 

Jan 25, 2010 at 10:20 AM
Edited Jan 25, 2010 at 10:32 AM

 

Hi Mr. Gunters

Thank you very much. I add a new file ArrayEx.cs with the code you specified.

No problem in compiling but same error during runtime.

I am new to C#. I am not very sure what went wrong... should I use System namespace or should I use my app namespace for ArrayEx?

 

Thanks!

PS: Sorry, I do not know what is a Stack trace or how to do it. Will be googling this term..

Jan 25, 2010 at 10:38 AM

Well, at the moment i don't know where in your code or your referenced code Array.Resize is called. I didn't find any Resize calls in JSON.Net and LinqBridge (the only external reference of JSON). The question is, when is this Resize called. Do you have a complete stack trace? If you run it in the debugger you should have one.

Does your RequestResult contain any objects from external libraries? Probably somehow JSON.NET calls code there during the deserialization. Only when you found the Resize call you can replace it with the (System.)ArrayEx.Resize from the code i posted.

 

Regards,

Gunter

 

Jan 25, 2010 at 10:38 AM

Got a screen capture of the stack trace.

Jan 25, 2010 at 10:53 AM

Hmm you are using System.Core.dll for the Linq-Functions. That means you are targeting CF 3.5 in your project but probably running on CF 2.0. How did you get System.Core.dll on the device?

The original JSON.Net binary is compiled against CF 3.5. If you really want to run on CF 2.0 you should compile JSON.Net yourself with a CF 2.0 project and compile LinqBridge yourself. Just create a new CF 2.0 project, put all the sources files from JSON.NET there, add a Conditional compilation symbol NET20, and replace Environment.Newline with "\r\n" and you should be set.

For LinqBridge: I just saw that the author has posted a single source file version of LinqBridge at code.google.com/p/linqbridge/downloads/list. Just include that in your CF 2.0 JSON.Net project.

 

Regards,

Gunter

Jan 25, 2010 at 11:17 AM

Hi

I tried to recreate a new CF 2.0 project; copied all the source codes and add to the project.

I am able to set Conditional compilation symbol NET20 but can't find where is the Environment.Newline with "\r\n"

 

When I try to compile, there are 244 errors... mostly like

Error    1    The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)    D:\CS_Projects\JSON_CF2PROJECT\JSON_CF2\Utilities\ConvertUtils.cs    28    14    JSON_CF2

Error    2    The type or namespace name 'ComponentModel' does not exist in the namespace 'System' (are you missing an assembly reference?)    D:\CS_Projects\JSON_CF2PROJECT\JSON_CF2\Utilities\ConvertUtils.cs    31    14    JSON_CF2

Error    3    The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)    D:\CS_Projects\JSON_CF2PROJECT\JSON_CF2\Utilities\ConvertUtils.cs    35    14    JSON_CF2

Error    4    The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)    D:\CS_Projects\JSON_CF2PROJECT\JSON_CF2\Utilities\BidirectionalDictionary.cs    28    14    JSON_CF2

etc, etc..

Jan 25, 2010 at 11:30 AM
Edited Jan 25, 2010 at 11:35 AM

Add LinqBridge-1.1.cs from http://code.google.com/p/linqbridge/downloads/list to your project.

Add a reference to System.Data to your project. You should reference mscorlib, System, System.Data and System.Xml.

You probably have to hack the LinqBridge source a bit to get it compile. I had to change some ArgumentOutOfRangeExceptions concstructor calls (just deleted the 2nd and 3rd argument) and i deleted LongCount and LongLength.

 

 

 

 

Jan 25, 2010 at 2:49 PM

Thank you for your help.

I guess this is beyond me as I have no idea how to hack LinqBridge

I added the references you mentioned but still I get 160 errors; 99% linq related.

 

Do you have an older version of the parser that is compatible to .net CF 2.0?

Oct 23, 2010 at 7:38 AM
gunters wrote:

Hi Ben,

I "patched" an earlier version (i think it was the rc before) of Json .NET to work with CF 2.0. By then Json .NET was not yet officially .NET 2.0 compatible (desktop version). It took me only a couple of hours to hack the sources, mostly adding some preprocessor definitions at hopefully the right places. I guess now that there is a 2.0-compatible version it should be even easier.

If you want to do it yourself I recommend to get the LinqBridge sources and compile them against CF 2.0 (that was only one small change i think), i got strange compile problems targeting the desktop binary of LinqBridge from my Json.NET CF-project.

If you don't want to do that and if James is ok with it i could send you my binaries of Json.NET and LinqBridge for CF 2.0 but you shouldn't expect support by either me or James if you encounter problems.

 

Regards,

Gunter

 Hi Gunter,

Can you please send me JSON.NET that works with CF 2.0? It will be very very helpful for me in current project.

Oct 23, 2010 at 10:22 AM

There you are J

Gunter

Von: insigno [mailto:notifications@codeplex.com]
Gesendet: Samstag, 23. Oktober 2010 09:39
An: gunter@gspranz.de
Betreff: Re: Version for .Net Compact Framework 2.0 [Json:74007]

From: insigno

gunters wrote:

Hi Ben,

I "patched" an earlier version (i think it was the rc before) of Json .NET to work with CF 2.0. By then Json .NET was not yet officially .NET 2.0 compatible (desktop version). It took me only a couple of hours to hack the sources, mostly adding some preprocessor definitions at hopefully the right places. I guess now that there is a 2.0-compatible version it should be even easier.

If you want to do it yourself I recommend to get the LinqBridge sources and compile them against CF 2.0 (that was only one small change i think), i got strange compile problems targeting the desktop binary of LinqBridge from my Json.NET CF-project.

If you don't want to do that and if James is ok with it i could send you my binaries of Json.NET and LinqBridge for CF 2.0 but you shouldn't expect support by either me or James if you encounter problems.

Regards,

Gunter

Hi Gunter,

Can you please send me JSON.NET that works with CF 2.0? It will be very very helpful for me in current project.

Read the full discussion online.

To add a post to this discussion, reply to this email (Json@discussions.codeplex.com)

To start a new discussion for this project, email Json@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Jul 6, 2011 at 6:52 PM

Hi Gunter,

I've been trying to compile my own version of JSON.NET for CF 2.0 but have been unsuccessful. Do you still have your version and are you still willing to share it? Your help would be much appreciated.

Jul 9, 2011 at 6:25 AM

Sure, here it is:

https://skydrive.live.com/embedicon.aspx/.Public/Json.Net%20CF%202.0.zip?cid=3f2c3852778103e9&sc=documents

Oct 4, 2011 at 4:24 PM

Saved my life @gunters!!

Dec 19, 2011 at 11:57 AM

Gunter!!! Amazing job!

Lost 2 days searching for a solution and u solved!

Thanks a lot man!

May 10, 2014 at 8:23 AM
hi,
friend !
can you send a the JSON.NET for CF 2.0?
email: yaogang89@hotmail.com thank you !
May 10, 2014 at 8:23 AM
hi,
friend !
can you send a the JSON.NET for CF 2.0?
email: yaogang89@hotmail.com thank you !
May 10, 2014 at 8:26 AM
Hi Gunter,
can you send a the JSON.NET for CF 2.0?
that address of your supplied i can't download !
email: yaogang89@hotmail.com thank you !