Implicit conversion from dynamic to ref struct is accepted by compiler but throws TypeLoadException #4713
Unanswered
KalleOlaviNiemitalo
asked this question in
Q&A
Replies: 1 comment 5 replies
-
It certainly shouldn't compile. Arguably we should block the conversion in the compiler, but that's a roslyn bug, not a csharplang one. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Inspired by dotnet/csharpstandard#282. The C# compiler allows an implicit conversion from
dynamic
to a reflike type such asSpan<byte>
, but the conversion throws TypeLoadException at run time. Should the C# language specification disallow this conversion, or should the C# compiler and the .NET Runtime find some way to make it work?Build with .NET SDK 5.0.202 targeting .NET 5.0, and run:
IL disassembly:
Beta Was this translation helpful? Give feedback.
All reactions