-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some System.Reflection.Emit implementations of Type.IsByRefLike
still throw NotSupportedException
: "Derived classes must provide an implementation"
#91532
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection-emit Issue DetailsDescriptionCertain System.Reflection.Emit (SRE) subclasses of I've so far found two such types that both seem to involve generics: Could it be that these two types were overlooked back in #34846? Reproduction StepsHere is one code example that reproduces the problem for var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("A"), AssemblyBuilderAccess.Run);
var moduleBuilder = assemblyBuilder.DefineDynamicModule("A");
var genericTypeBuilder = moduleBuilder.DefineType("C", TypeAttributes.Class);
_ = genericTypeBuilder.DefineGenericParameters("T");
var closedGenericTypeBuilder = genericTypeBuilder.MakeGenericType(typeof(object));
Console.WriteLine(closedGenericTypeBuilder.GetType().FullName);
Console.WriteLine(closedGenericTypeBuilder.IsByRefLike); (I haven't yet been able to create a short code repro for Expected behaviorPrints the following to the console:
Actual behaviorPrints the following to the console:
The exception is caused by the Regression?I don't think this is a regression, since the same error also occurs on older .NET runtimes (e. g. .NET Core 3.1). It appears like this simply hasn't been implemented yet at all. Known WorkaroundsI don't know of any workaround short of wrapping static bool IsByRefLikeSafe(this Type type)
{
try
{
return type.IsByRefLike;
}
catch (NotSupportedException)
{
return false;
}
} Configuration
Other informationNo response
|
I went through the codebase and found 4 types not implementing
|
I strongly suspect that the last one ( |
Worth noting that this might change, cc @jaredpar for progress on that |
In terms of updates on During the .NET 8 timeframe I was convinced that we can separate the design for So at this point it's more a question of where it fits in the priority ranking. |
Looks they should all return false, though I would leave |
Description
Certain System.Reflection.Emit (SRE) subclasses of
Type
appear to be missing an implementation for theType.IsByRefLike
property. When queried, aNotSupportedException
("Derived classes must provide an implementation") gets thrown when they should probably just returnfalse
.I've so far found two such types that both seem to involve generics:
System.Reflection.Emit.TypeBuilderInstantiation
andSystem.Reflection.Emit.SymbolType
.Could it be that these two types were overlooked back in #34846?
Reproduction Steps
Here is one code example that reproduces the problem for
System.Reflection.Emit.TypeBuilderInstantiation
:(I haven't yet been able to create a short code repro for
System.Reflection.Emit.SymbolType
, but will add one if I can figure it out.)Expected behavior
Prints the following to the console:
Actual behavior
Prints the following to the console:
The exception is caused by the
IsByRefLike
query in the last line of code.Regression?
I don't think this is a regression, since the same error also occurs on older .NET runtimes (e. g. .NET Core 3.1). It appears like this simply hasn't been implemented yet at all.
Known Workarounds
I don't know of any workaround short of wrapping
IsByRefLike
queries in an extension method that catches the exception and converts it tofalse
, then calling that extension method instead of usingIsByRefLike
directly:Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: