dotnet / dotnet/dotnet-api-docs

`Delegate.DynamicInvokeImpl(Object[])` – can `MemberAccessException` be really thrown by _private method_

Open
#7,542 1 comment 0 reactions 0 assignees View on GitHub
area-System.Runtime Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

From [Exceptions](https://docs.microsoft.com/en-us/dotnet/api/system.delegate.dynamicinvokeimpl?view=net-6.0#exceptions)

> MemberAccessException
The caller does not have access to the method represented by the delegate (for example, if the method is private).

I verified this in C# Interactive (.NET Core) but did not get `MemberAccessException`.

````csharp
> class A { void X() { Write ('X'); } public Delegate Del => X; }
> class B { Delegate x; public B ( Delegate x ) => this.x = x; public void X () => x.DynamicInvoke (); }
> new B(new A().Del).X()
X
````

Am I missing something? Perhaps this statement is only outdated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.