You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While playing around with the virtual method resolution algorithm in the crossgen project I noticed that the resolution algorithm does not handle a rare (synthetical) scenario where overriding methods are internal and made available for certain subclasses via the attribute InternalsVisibleTo.
While the runtime handles this accordingly with a MethodAccessException the method resolution for crossgen apparently does consider accessibility (at least it seems like it).
yields a System.MethodAccessException: Attempt by method 'C.ClassC.Main(System.String[])' to access method 'A.ClassA.M()' failed., as expected.
However when the provided test case above returns [A]A.ClassA::M(). The out parameter of the devirtualization has default value CORINFO_DEVIRTUALIZATION_UNKNOWN.
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
AnakinRaW
changed the title
Devirtualization for internal virtual overrides mismatches runtime behaviour
Devirtualization in CrossGen2 for internal virtual overrides mismatches runtime behaviour
Oct 28, 2021
ah, that's good to know.
Are there any plans this gets included to Crossgen2? If not, could someone maybe give me a small hint where in MetadataVirtualMethodAlgorithm.cs or DevirtualizationManager.cs this check should be added.
Description
While playing around with the virtual method resolution algorithm in the crossgen project I noticed that the resolution algorithm does not handle a rare (synthetical) scenario where overriding methods are
internal
and made available for certain subclasses via the attributeInternalsVisibleTo
.While the runtime handles this accordingly with a
MethodAccessException
the method resolution for crossgen apparently does consider accessibility (at least it seems like it).Reproduction Steps
I created the following assemblies:
I conducted the following test case:
Expected behavior
Running the same assemblies with with a given
Main
method inClassC
yields a
System.MethodAccessException: Attempt by method 'C.ClassC.Main(System.String[])' to access method 'A.ClassA.M()' failed.
, as expected.However when the provided test case above returns
[A]A.ClassA::M()
. The out parameter of the devirtualization has default valueCORINFO_DEVIRTUALIZATION_UNKNOWN
.The Roslyn Compiler guys already covered this issue to explicitly deny compilation in such a scenario. so maybe this helps in case my own words are too confusing ;)
https://github.com/dotnet/roslyn/blob/main/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs#L2044
Actual behavior
The
result
value on the 3rd case is expected to benull
because at runtime such an operation would fail in a MethodAccessException.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: