【发布时间】:2015-02-19 11:23:41
【问题描述】:
我正在尝试使用 ServiceStack 将简单的 json 字符串反序列化为 Dto 对象:
public class TestDto
{
public int MyProp { get; set; }
}
var json = JsonSerializer.DeserializeFromString<TestDto>("{\"MyProp\":6}");
我得到了例外:
[System.TypeInitializationException] =
{"The type initializer for 'ServiceStack.Text.Json.JsonReader`1' threw an exception."}
// With the inner exception:
"Object reference not set to an instance of an object."
// And the stack trace:
at ServiceStack.Text.Common.JsReader`1.GetCoreParseFn[T]()
at ServiceStack.Text.Common.JsReader`1.GetParseFn[T]()
at ServiceStack.Text.Json.JsonReader`1..cctor()
我正在使用 Windows 8.1 上的 Xamarin 在 Visual Studio 中进行开发。 ServiceStack 代码位于可移植库中。目前我正在直接从单元测试中触发可移植库代码。
这是 ServiceStack 的 Nuget 包信息:
<package id="ServiceStack.Text" version="4.0.36"
targetFramework="portable-net45+win+MonoAndroid10+xamarinios10+MonoTouch10" />
知道我在这里缺少什么吗?
【问题讨论】:
-
您使用的是什么版本的 SS.Text?您在哪个平台/操作系统上运行它?如果有的话,请提供您正在使用的任何其他配置。
-
嗨@mythz 我在问题的底部添加了一些额外的信息。
-
by Xamarin 您是指为 Android 还是 iOS 开发?
-
对不起,对于 iOS,但由于我是从单元测试触发它,所以我绕过 iOS 库并直接访问可移植库。
标签: json servicestack