[protocolbuffers/protobuf][C#] 将 .NET SDK 更新到 LTS 版本

2024-05-11 455 views
3

更新 SDK:

  • 2.1 -> 3.1
  • 5.0 -> 6.0

还修复了解析 JSON 格式的超出范围的双精度值时的不一致问题。

回答

8

@jtattermusch

6

由于一致性测试而失败:

错误,test=Required.Proto3.JsonInput.DoubleFieldTooSmall:应该解析失败,但没有。请求=json_payload:“{\”optionalDouble \“:-1.89769e + 308}”requested_output_format:JSON message_type:“protobuf_test_messages.proto3.TestAllTypesProto3”test_category:JSON_TEST,response=json_payload:“{\”optionalDouble \“:\”-无穷\” }”

这些测试失败了。如果现在无法修复它们,您可以将它们添加到故障列表中,以便整个套件能够成功。通过运行以下命令将它们添加到失败列表: ./update_failure_list.py failure_list_csharp.txt --addfailing_tests.txt

必需.Proto3.JsonInput.DoubleFieldTooSmall

.NET 中的 Double.Parse 方法用于解析 JSON 中的双精度数。对于 .NET Core 3.1 及更高版本,现在支持预计会失败的小值。

忽略错误?或者在 Protobuf 的双重解析中添加额外的逻辑以显式地使这个小值失败?

0

dotnet restore看起来我们再次在 Windows 上 看到失败: https://source.cloud.google.com/results/invocables/1f3042e9-d6f9-4e45-a237-4f1fa4cc9979/log

例如

T:\src\github\protobuf\csharp\src\Google.Protobuf.Benchmarks\Google.Protobuf.Benchmarks.csproj : error NU1101: Unable to find package BenchmarkDotNet. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [T:\src\github\protobuf\csharp\src\Google.Protobuf.sln]

T:\src\github\protobuf\csharp\src\Google.Protobuf.Benchmarks\Google.Protobuf.Benchmarks.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Ref. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [T:\src\github\protobuf\csharp\src\Google.Protobuf.sln]

T:\src\github\protobuf\csharp\src\Google.Protobuf\Google.Protobuf.csproj : error NU1102: Unable to find package NETStandard.Library with version (>= 1.6.1) [T:\src\github\protobuf\csharp\src\Google.Protobuf.sln]

T:\src\github\protobuf\csharp\src\Google.Protobuf\Google.Protobuf.csproj : error NU1102:   - Found 1 version(s) in Microsoft Visual Studio Offline Packages [ Nearest version: 1.6.0 ] [T:\src\github\protobuf\csharp\src\Google.Protobuf.sln]

T:\src\github\protobuf\csharp\src\Google.Protobuf\Google.Protobuf.csproj : error NU1101: Unable to find package Microsoft.SourceLink.GitHub. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [T:\src\github\protobuf\csharp\src\Google.Protobuf.sln]

T:\src\github\protobuf\csharp\src\Google.Protobuf\Google.Protobuf.csproj : error NU1101: Unable to find package Microsoft.NETFramework.ReferenceAssemblies. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [T:\src\github\protobuf\csharp\src\Google.Protobuf.sln]

我想知道为什么它只抱怨 nuget 源“Microsoft Visual Studio Offline Packages”。 nuget 源是否配置错误,导致永远不会尝试从 nuget.org 下载?

5

-1.89769e+308

这很奇怪。 .NET Core 3+ 中输入值太小,Double.Parse 如何突然成功?

Double.MinValue-1.7976931348623157E+308(参见https://docs.microsoft.com/en-us/dotnet/api/system.double.minvalue?view=net-5.0),因此能够解析测试值-1.89769e+308(显然要小得多)像虫子一样。我们应该为此添加一个 C# 单元测试,并确保我们了解发生了什么。

4

根据文档,“仅限 NET Framework 和 .NET Core 2.2 及更早版本”中的 Double.parse 引发了 OverflowException,因此确实发生了变化。我不确定是什么。

8

好的,看起来现在在这些情况下返回 +/- Inf。

8

“在 .NET Core 3.0 及更高版本中,根据 IEEE 754 规范的要求,太大而无法表示的值将舍入为 PositiveInfinity 或 NegativeInfinity。在以前的版本(包括 .NET Framework)中,解析太大而无法表示的值会导致失败。”

0

这会很棘手。我们可能不想简单地接受无穷大的值。相反,我们可能想显式检查它们,然后像​​在 2.1 及更早版本中那样失败。

3

简单的解决方案可能是如果返回无穷大则抛出异常Double.Parse。这符合现有的行为。

0

@jtattermusch

我想知道为什么它只抱怨 nuget 源“Microsoft Visual Studio Offline Packages”。 nuget 源是否配置错误,导致永远不会尝试从 nuget.org 下载?

我不知道。也许较新的 SDK 发生了一些变化,要求显式配置包源?我向此 PR 添加了一个 nuget.org 文件,以显式地将 nuget.org 配置为源。