C# 14 breaking change heads up
Hey folks, as part of our smoke testing for .NET 10, we noticed that grandnode2 is impacted by a breaking change in .NET 10 related to https://github.com/dotnet/roslyn/blob/main/docs/compilers/CSharp/Compiler%20Breaking%20Changes%20-%20DotNet%2010.md#spant-and-readonlyspant-overloads-are-applicable-in-more-scenarios-in-c-14-and-newer. When building on dotnet-sdk-10.0.100-rc.2.25474.116, you may encounter errors like:
The call is ambiguous between the following methods or properties: 'JsonSerializer.Deserialize<TValue>(ReadOnlySpan<byte>, JsonSerializerOptions?)' and 'JsonSerializer.Deserialize<TValue>(string, JsonSerializerOptions?)'
This occurs because, starting with .NET 10, the overloads for JsonSerializer.Deserialize were updated, and code that passes a parameter of type 'object' or 'var' (where the type could be either string or byte span) can no longer be resolved automatically by the compiler. This leads to build failures.
To address this, you’ll need to update your code to explicitly cast the parameter to either string or ReadOnlySpan
C#
// For string input
JsonSerializer.Deserialize<TValue>((string)input, options);
// For byte input
JsonSerializer.Deserialize<TValue>((ReadOnlySpan<byte>)input, options);
Alternatively, ensure that your code always passes the correct type matching the method signature, or upgrade any dependencies that may be affected by this change.
Please get details from https://github.com/dotnet/sdk/issues/51022 if you need them.
Just wanted to give a heads-up so you can plan for a smooth transition to .NET 10!
@CancanTang Thanks for catching this and for the detailed breakdown! We’ll keep an eye on this and start making the necessary adjustments once .NET 10 is officially out. Really appreciate the early notice — that’ll definitely save us some headaches later 🙂