From ca9b9874605cdcc1c4ed33b6b78c5607f51c904f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksey=20Kliger=20=28=CE=BBgeek=29?= Date: Fri, 29 May 2020 15:30:41 -0400 Subject: [PATCH] [mono] Remove some dead code from Delegate.DynamicInvoke (#37085) * [mono] Remove some dead code from System.Delegate.DynamicInvokeImpl Remove some dead code from `System.Delegate.DynamicInvoke`. It should be the case that `Method` is non-`null` when we call `DynamicInvoke` - the delegate method should be known at the time of the invoke, and it should not be picked based on the arguments. Fixes https://github.com/dotnet/runtime/issues/37008 --- .../System.Private.CoreLib/src/System/Delegate.Mono.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs index 938eecd..6e991de 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs @@ -422,18 +422,7 @@ namespace System protected virtual object? DynamicInvokeImpl(object?[]? args) { - if (Method is null) - { -#nullable disable - // FIXME: This code cannot handle null argument values - Type[] mtypes = new Type[args.Length]; - for (int i = 0; i < args.Length; ++i) - { - mtypes[i] = args[i].GetType(); - } - method_info = _target.GetType().GetMethod(data.method_name, mtypes); -#nullable restore - } + MethodInfo _method = Method ?? throw new NullReferenceException ("method_info is null"); object? target = _target; @@ -458,7 +447,7 @@ namespace System } } - if (Method!.IsStatic) + if (_method.IsStatic) { // // The delegate is bound to _target @@ -489,7 +478,7 @@ namespace System } } - return Method.Invoke(target, args); + return _method.Invoke(target, args); } public override bool Equals(object? obj) -- 2.7.4