-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Update .NET adapter to handle interface static members properly #15908
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, could we benefit from a source generator to pre-build the cache at compile time or this will force to load extra assemblies at startup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@daxian-dbw Please respond to Rob's comments. |
All comments are addressed. Please take another look, thanks! |
Its worth calling out that, aside from I would have expected that such members were at least not preferred over matching public members (even once powershell can properly support |
A basic breaking-change issue documenting this has been created here: https://github.com/dotnet/runtime/issues/57323 |
🎉 Handy links: |
🎉 Handy links: |
PR Summary
After switching to the latest dotnet 6 preview.7 SDK, we started to see the "Bad IL format" failure as shown below (see the reported dotnet bug here).
This is because a new preview feature is enabled in preview.7, which allows an interface to have abstract static methods (see the blog post). The type
System.Int16
implements much more interfaces in preview.7, and many of them declare abstract static properties. However, the abstract static properties cannot be invoked withGetValue(null)
reflection API, and doing so results in thisBad IL format
error.The recommendation from .NET team is to ignore static virtual/abstract members on an interface, especially as the set of APIs may change with .NET 7.
This PR includes the following changes:
DisablePrivateReflectionAttribute
is already obsolete and there is no restriction on private reflection in .NET Core, removeDisallowPrivateReflection
and uses of it from our code.PopulateMethodReflectionTable
handles interface was to calltype.GetInterfaceMap(interfaceType)
and use the interface methods from the returned mapping object. The static non-virtual methods on an interface will be missed in this way, so, this is changed to callinterfaceType.GetMethods(bindingFlags)
directly.MethodCacheEntry
constructor, to avoid unneeded array creation.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.