error CS8640: Expression tree cannot contain value of ref struct or restricted type 'ReadOnlySpan' too restrictive #31957
Labels
Area-Compilers
Feature Request
New Language Feature - Ref Locals and Returns
Ref Locals and Returns
Tenet-Compatibility
Violation of forwards/backwards compatibility in a design-time piece.
Milestone
Version Used:
3.0.100-preview-009844
Steps to Reproduce:
In Preview1 and in previous versions the following code snippet produced a valid MethodInfo for the generic static method with a byref struct, since #30776 it does not compile anymore.
Motivation:
As many probably know, finding the correct MethodInfo for reflection (or in this case Expression Trees in SpanJson) for extension methods and/or methods with generic arguments is a bit of work, especially if the there are multiple overloads with the same name (LINQ's IEnumerable...)
One of the more generally accepted shortcuts is to use an expression tree to describe the method and obtain the MethodInfo like above. This works nicely with pretty much everything.
Unfortunately in #30776 you now prevent this via the following compilation error:
error CS8640: Expression tree cannot contain value of ref struct or restricted type 'ReadOnlySpan'.
Isn't there maybe a less restrictive bugfix which still allows the above way to work, as the above Expression is never executed or compiled?
Expected Behavior:
I get the MethodInfo for
AsBytes
for the generic argumentchar
and the parameterReadOnlySpan<char>
.Actual Behavior:
error CS8640: Expression tree cannot contain value of ref struct or restricted type 'ReadOnlySpan'.
The text was updated successfully, but these errors were encountered: