将 json 整数反序列化为长整数会导致异常和空值,看似随机

Deserializing json integers to longs results in exceptions and null values, seemingly randomly

我遇到了突然出现的最奇怪的问题:

在某些(许多)情况下,突然地,解析包含 long 的 DTO 失败,具体取决于 long 的值。让我们看看发生了什么。我正在使用 ServiceStack 和 Visual Studio 2017,.NET Framework 4.7.2.

服务

[Tag("Notifications")]
[Route(Misc.BASE_PATH, "PUT")]
public class SetActorNotificationsRead : IReturn<SetActorNotificationsReadResponse>
{
    public List<string> NotificationIds { get; set; }
    public List<string> Test { get; set; }
    public long MyLong { get; set; }
}

我通过 Postman 调用它,如下所示:

在这种情况下,它按预期工作,正确填充了 DTO:

如果我将 MyLong 更改为 1234,它会失败并显示

Could not load file or assembly 'System.Numerics.Vectors

但如果我将其更改为 12345,它会再次起作用:

更糟糕的是,如果我将 NotificationIds 更改为 List<long>,它会变得更奇怪:

此 Postman 调用失败,因为 NotificationIds 列表为空:

但如果我更改请求,并在四个 9:s 前面添加一个零,则它有效:

如果我做 [ 9999, 123 ]NotificationIds 仍然是 null,但是如果我做 [ 09999, 123 ],或者 [ 99991, 123 ] 它不是 null,并且两个值都在列表中.

我一无所知。有什么想法吗?

由于无法加载 'System.Numerics.Vectors' 程序集的运行时依赖性问题,问题出在异常中。

你可以试试.

来自包裹:https://www.nuget.org/packages/System.Numerics.Vectors