Skip to content

Commit

Permalink
Throw NullRef in some delegate construction scenarios (dotnet#71526)
Browse files Browse the repository at this point in the history
Apparently constructing a delegate to a virtual/interface method throws `NullReferenceException` instead of `ArgumentException` (that is thrown for non-virtual cases).

System.Collections.Immutable tests are testing for this for some reason.
  • Loading branch information
MichalStrehovsky authored Jul 1, 2022
1 parent fddb387 commit 5e088b0
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void InitializeClosedInstanceSlow(object firstParameter, IntPtr function
private void InitializeClosedInstanceWithGVMResolution(object firstParameter, RuntimeMethodHandle tokenOfGenericVirtualMethod)
{
if (firstParameter is null)
throw new ArgumentException(SR.Arg_DlgtNullInst);
throw new NullReferenceException();

IntPtr functionResolution = TypeLoaderExports.GVMLookupForSlot(firstParameter, tokenOfGenericVirtualMethod);

Expand Down Expand Up @@ -185,7 +185,7 @@ private void InitializeClosedInstanceWithGVMResolution(object firstParameter, Ru
private void InitializeClosedInstanceToInterface(object firstParameter, IntPtr dispatchCell)
{
if (firstParameter is null)
throw new ArgumentException(SR.Arg_DlgtNullInst);
throw new NullReferenceException();

m_functionPointer = RuntimeImports.RhpResolveInterfaceMethod(firstParameter, dispatchCell);
m_firstParameter = firstParameter;
Expand Down

0 comments on commit 5e088b0

Please sign in to comment.