https://bugs.winehq.org/show_bug.cgi?id=32316
--- Comment #19 from Bruni earns.61@gmail.com --- Anastasius Thank you for your hard work!
Got a working test case.
The essense is that the bug can be unvealed by detecting the method name which threw exceptions when AddEventHandler was called with null target parameter.
There is clear difference between Mono and .NET behavior - the former throw Exception in CreateAddEventDelegate whereas the latter do it in Invoke method.
Compiled with Microsoft csc.exe, it prints "testcase passed" Compiled and run by means of Mono, it prints "testcase failed" and stops running.
using System; using System.Text; using System.Reflection; using System.Diagnostics;
namespace AddEventHandlerTestCase { class Program { public event Func<string> TestEvent;
public string TestMethod() { return "Hello World"; }
public void Test() { if (TestEvent != null) Console.WriteLine(TestEvent()); }
static void Main(string[] args) { var p = new Program(); EventInfo eventInfo = p.GetType().GetEvent("TestEvent"); var methodInfo = p.GetType().GetMethod("TestMethod"); Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, p, methodInfo); try { eventInfo.AddEventHandler(null, handler);
} catch (Exception e) { if (!e.StackTrace.Contains("System.Reflection.RuntimeMethodInfo.Invoke")) { Console.WriteLine("testcase failed"); Debugger.Break(); } else { Console.WriteLine("testcase passed"); Console.ReadLine(); } } } } }