Workaround a C++/CLI bug involving DIMs - #89253
Conversation
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
Tagging subscribers to this area: @dotnet/area-system-numerics Issue Detailsnull
|
jeffhandley
left a comment
There was a problem hiding this comment.
This temporary workaround looks good to me, with the understanding that we'll revert it once the C++/CLI team applies their fix and we take that update into dotnet/wpf.
|
/backport to release/8.0-preview7 |
|
Started backporting to release/8.0-preview7: https://github.com/dotnet/runtime/actions/runs/5614063183 |
As per the title there is currently a C++/CLI bug involving implementing an instance DIM on a derived interface. This causes C++/CLI to error when using any type that implements such an interface, which in the case of
System.Numerics.INumberBase<TSelf>includes all the primitive types (such asInt32orSingle).There were a few possible changes that would temporarily resolve this issue...
IUtf8SpanFormattableto have a DIM where it always throwsPlatformNotSupportedException, but this could lead to unexpected behavior for consumers of the APIIUtf8SpanFormattableto have a DIM where it always returnsfalse, but this risks users naively doing the wrong thing and trying to grow the buffer and call the API repeatedly as that's how the otherTryFormatAPIs workIUtf8SpanFormattableto inherit fromISpanFormattableand have a DIM where it defers to that implementationOf these options, 1 or 4 are the least risky.
4 would end up changing the shipping API surface and would not require a reversion later. It has the downside in that it requires everyone implementing
IUtf8SpanFormattableto also supportISpanFormattable(that isUTF-16). This puts more restriction on the API surface overall. That being said, it is the better option if we believe that the C++/CLI fix will not make the .NET 8 release as avoids us introducing a diamond problem in the future as the DIM is provided in the same release that the relevant interface and API are defined.1 (this change) will require us to revert this PR once the C++/CLI fix goes in. Not reverting this workaround will result in
INumberBase<TSelf>not being able to implementIUtf8SpanFormattablewithout risking the introduction of a diamond problem, since other types/interfaces could implementIUtf8SpanFormattablewith a DIM before the .NET 9 release.