2

I'm porting a Xamarin.IOS project to the Unified version of it and I'm facing an issue using the ServiceStack.Text package. I've added it to the project using NuGet.

So I made a new empty project on Xamarin to test it and the problem remains the same, so, here is the test project code:

using UIKit;
using ServiceStack.Text;
using System;

namespace ServiceStackTester
{
    public class Test {
        public string Field1 { get; set;}
        public string Field2 { get; set;}
    }

    public class Application
    {
        // This is the main entry point of the application.
        static void Main (string[] args)
        {
            Test t = JsonSerializer.DeserializeFromString<Test>("{Field1:\"A\",Field2:\"B\"}");
            Console.WriteLine (t.Field1);

            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main (args, null, "AppDelegate");
        }
    }
}

JsonSerializer.DeserializeFromString causes this error:

    System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.Text.Json.JsonReader`1 
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.Text.Json.JsonReader 
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.Text.Common.JsReader`1 
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.Text.Common.JsWriter 
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.Text.JsConfig 
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.LicenseUtils 
---> System.Exception: Object reference not set to an instance of an object

at ServiceStack.LicenseUtils..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.JsConfig..cctor () [0x00051] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.Common.JsWriter..cctor () [0x0005a] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.Common.JsReader`1[ServiceStack.Text.Json.JsonTypeSerializer]..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.Json.JsonReader..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.Json.JsonReader`1[ServiceStackTester.Test]..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.JsonSerializer.DeserializeFromString[Test] (System.String value) [0x00012] in <filename unknown>:0
at ServiceStackTester.Application.Main (System.String[] args) [0x00006] in /Users/daniele/Projects/ServiceStackTester/ServiceStackTester/Main.cs:17

Is it a licensing problem or I miss something? Thanks, Daniele

Daniele P.
  • 228
  • 4
  • 16

1 Answers1

1

I think your missing the double quotes around the name of your fields.

"{\"Field1\":\"A\",\"Field2\":\"B\"}"

Would do the trick.

ChristiaanV
  • 5,401
  • 3
  • 32
  • 42
  • You're right but it doesn't solve the problem. So I've changed library, moving to Newtonsoft.Json and it works with both versions of the json string. – Daniele P. Oct 02 '15 at 08:35