https://bugs.winehq.org/show_bug.cgi?id=32316
--- Comment #21 from Bruni earns.61@gmail.com --- Esme, please take a look at a new testcase. It passes on native .NET but fails on Mono
Thanks!
using System; using System.Reflection; using System.Diagnostics;
namespace AddEventHandlerTestCase { class Program { private MulticastDelegate m_MulticastDelegate = null; public delegate void DelegateFunction(int iValue); public event DelegateFunction EventSource { add { throw new NotSupportedException(); } remove { } }
public void TestMethod(int i) { }
static void Main(string[] args) { var p = new Program(); EventInfo eventInfo = p.GetType().GetEvent("EventSource"); var methodInfo = p.GetType().GetMethod("TestMethod"); Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, p, methodInfo);
try { eventInfo.AddEventHandler(p, handler); } catch (NotSupportedException e) { Console.WriteLine("Testcase failed"); Console.WriteLine("NotSupportedException has been catched and it is not wrapped by "); Console.WriteLine("TargetInvocationException"); Console.WriteLine("TargetInvocationException was expected as NotSupportedException "); Console.WriteLine("was thrown in an event accessor method invoked through reflection."); Console.WriteLine("See ");
Console.WriteLine("docs.microsoft.com/en-us/search/?terms=TargetInvocationException"); Console.WriteLine("Stacktrace:" + e.StackTrace.ToString()); Debugger.Break(); } catch (TargetInvocationException e) { Console.WriteLine("Testcase passed"); string eInnerExceptionText = e.InnerException.ToString(); string[] exceptionlines = eInnerExceptionText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
Console.WriteLine("TargetInvocationException has been catched and has inner exception."); Console.WriteLine("Inner exception has a type of " + e.InnerException.GetType()); Console.WriteLine("Inner exception object was created by:" + exceptionlines[1]); Console.WriteLine("Stacktrace:" + e.StackTrace.ToString()); Console.ReadLine(); } } } }