Forum Cross Platform with Xamarin

Using ServiceStack.Text in Xamarin.Forms / PCL app?

I'm trying to move from the Newtonsoft JSON library to ServiceStack.Text for handling JSON in my app (for performance reasons), but I am having trouble getting this library to work.

I've added the ServiceStack.Text Nuget packages to the projects, but when I try to use the library, I get an exception:
2016-07-25 16:23:53.059 HomeWaveiOS[21276:6222447] Warning: Unhandled exception: System.TypeInitializationException: The type initializer for 'ServiceStack.Text.JsConfig' threw an exception. ---> System.TypeInitializationException: The type initializer for 'ServiceStack.LicenseUtils' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object
at ServiceStack.LicenseUtils..cctor () [0x00000] in :0

(code: ColorSet is a simple Dictionary<string, string>)
JsConfig.InitStatics(); // <-- Exception occurs here
JsConfig.IncludePublicFields = true;
string cpJson = ColorSet.ToJson();

Others have run into similar issues, and for some of them the solution was to run some client initialisation code (on the platform-specific project), however the code involved in that init call is not inluded in ServiceStack.Text (it's inServiceStack.Client). ServiceStack.Text is supposed to be independent and shouldn't require the Client part.

Has anyone managed to get ServiceStack.Text working under Xamarin?

Best Answer

Answers

Sign In or Register to comment.