Repository navigation
Throw MemberAccessException for reflection calls to static abstract methods #135566
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
Open
caraioniurie47
wants to merge
5
commits into
dotnet:main
Choose a base branch
from
caraioniurie47:issue-135565
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+535
−15
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
317030a
Keep static abstract methods out of invoke map
caraioniurie47 984d005
Move static abstract invoke tests to System.Reflection.Tests
caraioniurie47 47ced63
Throw MemberAccessException for static abstract
caraioniurie47 42614b3
Check static abstract in BindToMethodInfo
caraioniurie47 7220f15
Move static abstract check to MethodDesc
caraioniurie47 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
....Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/StaticAbstractMethodInvoker.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Reflection; | ||
|
|
||
| using Internal.Reflection.Core.Execution; | ||
|
|
||
| namespace System.Reflection.Runtime.MethodInfos | ||
| { | ||
| // A static abstract interface method has no implementation to call: invoking it or binding a delegate to it throws | ||
| // MemberAccessException, as on CoreCLR. Taking its address throws PlatformNotSupportedException, as for other | ||
| // abstract methods. | ||
| internal sealed class StaticAbstractMethodInvoker : MethodBaseInvoker | ||
| { | ||
| private readonly MethodInfo _method; | ||
|
|
||
| public StaticAbstractMethodInvoker(MethodInfo method) | ||
| { | ||
| _method = method; | ||
| } | ||
|
|
||
| private MemberAccessException CreateException() | ||
| { | ||
| return new MemberAccessException(SR.Format(SR.Acc_CallStaticAbstract, _method.DeclaringType, _method.Name)); | ||
| } | ||
|
|
||
| protected sealed override object? Invoke(object? thisObject, object?[]? arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) | ||
| { | ||
| throw CreateException(); | ||
| } | ||
|
|
||
| protected sealed override object CreateInstance(object?[]? arguments, BinderBundle binderBundle, bool wrapInTargetInvocationException) | ||
| { | ||
| throw CreateException(); | ||
| } | ||
|
|
||
| protected internal sealed override object CreateInstance(Span<object?> arguments) | ||
| { | ||
| throw CreateException(); | ||
| } | ||
|
|
||
| protected internal sealed override object CreateInstanceWithFewArgs(Span<object?> arguments) | ||
| { | ||
| throw CreateException(); | ||
| } | ||
|
|
||
| protected internal sealed override object? Invoke(object? thisObject, Span<object?> arguments) | ||
| { | ||
| // MethodInvoker.Invoke(object, Span<object>) leaves the argument count check to the invoker, unlike its | ||
| // fixed-arity overloads, which check before calling InvokeDirectWithFewArgs. Check the count here first, as | ||
| // DynamicInvokeInfo does for other methods, so a wrong count throws TargetParameterCountException. | ||
| if (arguments.Length != _method.GetParametersAsSpan().Length) | ||
| throw new TargetParameterCountException(SR.Arg_ParmCnt); | ||
|
|
||
| throw CreateException(); | ||
| } | ||
|
|
||
| protected internal sealed override object? InvokeDirectWithFewArgs(object? thisObject, Span<object?> arguments) | ||
| { | ||
| throw CreateException(); | ||
| } | ||
|
|
||
| public sealed override Delegate CreateDelegate(RuntimeTypeHandle delegateType, object target, bool isStatic, bool isVirtual, bool isOpen) | ||
| { | ||
| throw CreateException(); | ||
| } | ||
|
|
||
| public sealed override IntPtr LdFtnResult | ||
| { | ||
| get | ||
| { | ||
| throw new PlatformNotSupportedException(); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.