Jump to content

Json serialization


Recommended Posts

I have lots of experience with .NET and C# under Windows but I'm totally new to KSP addon development and also to Mono. This got me into a situation I don't quite understand ;)

I want to develop an addon which communicates with a REST service on a server. The server is written in nodejs and responds with json formatted data. To test the communication without always waiting on KSP to start up I wrote a separate little console application and everythings works great.

Now moving to an actual KSP addon I get an exception and the confusion starts:

[Exception]: FileNotFoundException: Could not load file or assembly 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.

I use the DataContractJsonSerializer type to (de-)serialize json data, which is causing the CLR to look for the System.Runtime.Serialization assembly. Looking at KSP_Data\Managed I realized that this assembly is in fact missing.

What are my options from here?

Mono has an implementation of this assembly but I don't know in what version of Mono it was added and I also can't find out what version of Mono KSP (1.0.2) or Unity (4.6.4f1) is using.

Thanks for any help.

- - - Updated - - -

lol, right after posting this I found a working solution, but I'm not quite sure if it is the "correct" or best solution:

- Compile against the .NET Framework 3.5 not 4.0 because the DataContractJsonSerializer was moved from System.ServiceModel.Web to System.Runtime.Serialization in 4.0.

- Copy System.ServiceModel.Web.dll and System.Runtime.Serialization.dll from Mono to KSP_Data\Managed. I copied it from my Unity installation from: Unity\Editor\Data\Mono\lib\mono\2.0

I am still confused by what version of Mono is used and what version of the .NET framework that relates to.

Link to comment
Share on other sites

There is also a serializer used by KSP, the ConfigNode class. It's what's used in the save files and settings files, and most mods use it.

Edit: Disregard that, must've read over the part where you said you wanted to comunicate with a server.

Edited by MrHappyFace
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...