ServiceStack:属性为空时获取 FileNotFoundException?
ServiceStack: Getting FileNotFoundException when properties are null?
我正在使用 ServiceStack 并发现了一些奇怪的东西。当 WS Dto 包含一些 null
值时,我在 System.Numerics.Vectors
上得到 FileNotFoundException
。例如,我有一个名为 "GetBookingSolutions" 的 Dto,它看起来像这样:
[Route(BookingWizard.BASE_PATH + "getbookingsolution", Verbs = "POST", Summary = "Sends booking spec to request server to create/plan the booking")]
public class GetBookingSolution : IReturn<GetBookingSolutionResponse>
{
public DateTime TimeWanted { get; set; }
public uint AddressFrom { get; set; }
// ...
public Dictionary<uint, int> Equipment { get; set; }
public Dictionary<uint, int> CoTravellers { get; set; }
}
最后两个是字典,因此是可为空的对象。如果发送客户端发送如下所示的 JSON:
{
"TimeWanted": "2018-12-10T09:05:00.000Z",
"AddressFrom": 14427162,
"CoTravellers": null,
"Equipment": null
}
然后我得到异常,如下所示。永远不会执行服务实现,因此永远不会到达代码。相反,我在 UncaughtExceptionHandlers
.
中得到异常
如果 JSON 看起来像这样:
{
"TimeWanted": "2018-12-10T09:05:00.000Z",
"AddressFrom": 14427162,
}
或者如果词典已填充:
{
"TimeWanted": "2018-12-10T09:05:00.000Z",
"AddressFrom": 14427162,
"CoTravellers": {
"13486513": 2,
"13486515": 1
},
"Equipment": {
"13424459": 2,
}
}
那么错误就不会出现了。为什么会这样?这是一个错误还是这里的建议是什么?如果最终用户未设置,null
值适用于这些属性。
System.IO.FileNotFoundException: Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.SpanHelpers.SequenceEqual(Byte& first, Byte& second, NUInt length)
at System.MemoryExtensions.Equals(ReadOnlySpan`1 span, ReadOnlySpan`1 other, StringComparison comparisonType)
at ServiceStack.Text.Json.JsonTypeSerializer.EatValue(ReadOnlySpan`1 value, Int32& i)
at ServiceStack.Text.Common.DeserializeTypeRefJson.StringToType(ReadOnlySpan`1 strType, TypeConfig typeConfig, EmptyCtorDelegate ctorFn, KeyValuePair`2[] typeAccessors)
at ServiceStack.Text.Common.DeserializeType`1.StringToTypeContext.DeserializeJson(ReadOnlySpan`1 value)
at ServiceStack.Text.Json.JsonReader.<>c__DisplayClass3_0.<GetParseSpanFn>b__0(ReadOnlySpan`1 v)
at ServiceStack.Text.JsonSerializer.DeserializeFromSpan(Type type, ReadOnlySpan`1 value)
at ServiceStack.Text.DefaultMemory.Deserialize(MemoryStream ms, Boolean fromPool, Type type, DeserializeStringSpanDelegate deserializer)
at ServiceStack.Text.DefaultMemory.<DeserializeAsync>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.RestHandler.<CreateRequestAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.RestHandler.<CreateRequestAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.RestHandler.<ProcessRequestAsync>d__14.MoveNext()
这是一个运行时依赖性问题,与 DTO 中的 null 无关,这正是触发需要 System.Numerics.Vectors 依赖性的代码路径的原因它无法加载。在这种情况下调用 System.MemoryExtensions.Equals()
扩展方法。
似乎有一个 few issues with this Exception and it looks like this GitHub Thread 有一些您可以尝试的解决方法。
我正在使用 ServiceStack 并发现了一些奇怪的东西。当 WS Dto 包含一些 null
值时,我在 System.Numerics.Vectors
上得到 FileNotFoundException
。例如,我有一个名为 "GetBookingSolutions" 的 Dto,它看起来像这样:
[Route(BookingWizard.BASE_PATH + "getbookingsolution", Verbs = "POST", Summary = "Sends booking spec to request server to create/plan the booking")]
public class GetBookingSolution : IReturn<GetBookingSolutionResponse>
{
public DateTime TimeWanted { get; set; }
public uint AddressFrom { get; set; }
// ...
public Dictionary<uint, int> Equipment { get; set; }
public Dictionary<uint, int> CoTravellers { get; set; }
}
最后两个是字典,因此是可为空的对象。如果发送客户端发送如下所示的 JSON:
{
"TimeWanted": "2018-12-10T09:05:00.000Z",
"AddressFrom": 14427162,
"CoTravellers": null,
"Equipment": null
}
然后我得到异常,如下所示。永远不会执行服务实现,因此永远不会到达代码。相反,我在 UncaughtExceptionHandlers
.
如果 JSON 看起来像这样:
{
"TimeWanted": "2018-12-10T09:05:00.000Z",
"AddressFrom": 14427162,
}
或者如果词典已填充:
{
"TimeWanted": "2018-12-10T09:05:00.000Z",
"AddressFrom": 14427162,
"CoTravellers": {
"13486513": 2,
"13486515": 1
},
"Equipment": {
"13424459": 2,
}
}
那么错误就不会出现了。为什么会这样?这是一个错误还是这里的建议是什么?如果最终用户未设置,null
值适用于这些属性。
System.IO.FileNotFoundException: Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.SpanHelpers.SequenceEqual(Byte& first, Byte& second, NUInt length)
at System.MemoryExtensions.Equals(ReadOnlySpan`1 span, ReadOnlySpan`1 other, StringComparison comparisonType)
at ServiceStack.Text.Json.JsonTypeSerializer.EatValue(ReadOnlySpan`1 value, Int32& i)
at ServiceStack.Text.Common.DeserializeTypeRefJson.StringToType(ReadOnlySpan`1 strType, TypeConfig typeConfig, EmptyCtorDelegate ctorFn, KeyValuePair`2[] typeAccessors)
at ServiceStack.Text.Common.DeserializeType`1.StringToTypeContext.DeserializeJson(ReadOnlySpan`1 value)
at ServiceStack.Text.Json.JsonReader.<>c__DisplayClass3_0.<GetParseSpanFn>b__0(ReadOnlySpan`1 v)
at ServiceStack.Text.JsonSerializer.DeserializeFromSpan(Type type, ReadOnlySpan`1 value)
at ServiceStack.Text.DefaultMemory.Deserialize(MemoryStream ms, Boolean fromPool, Type type, DeserializeStringSpanDelegate deserializer)
at ServiceStack.Text.DefaultMemory.<DeserializeAsync>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.RestHandler.<CreateRequestAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.RestHandler.<CreateRequestAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.RestHandler.<ProcessRequestAsync>d__14.MoveNext()
这是一个运行时依赖性问题,与 DTO 中的 null 无关,这正是触发需要 System.Numerics.Vectors 依赖性的代码路径的原因它无法加载。在这种情况下调用 System.MemoryExtensions.Equals()
扩展方法。
似乎有一个 few issues with this Exception and it looks like this GitHub Thread 有一些您可以尝试的解决方法。