From: pius.lee Date: Tue, 15 Nov 2016 06:49:52 +0000 (+0900) Subject: Add Unhandled Exception handler for Dlog output X-Git-Tag: submit/tizen/20161214.063015~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1996eaf33451d4c9ceb207247c8c2f33107ab09;p=platform%2Fcore%2Fdotnet%2Flauncher.git Add Unhandled Exception handler for Dlog output Add temporarily implmentation until become Appdomain on API Change-Id: I6c622d701d94cf3cc29262e066a490f102cfd46b --- diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs index 39ff2fa..acbb06e 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs @@ -78,10 +78,33 @@ namespace Tizen.Runtime.Coreclr } } + public static void UnhandledExceptionHandler(object sender, object args) + { + TypeInfo unhandledExceptionEventArgsType = + Type.GetType("UnhandledExceptionEventArgs").GetTypeInfo(); + + PropertyInfo exception = unhandledExceptionEventArgsType.GetProperty("ExceptionObject"); + Exception e = (Exception)exception.GetValue(args); + + PrintException(e); + } + public static bool Initialize(string preloadDirectory) { try { + // Set UnhandledException handler with reflection + // we must replace this to no reflection method after AppDomain is comming in used net standard + TypeInfo appdomainType = Type.GetType("System.AppDomain").GetTypeInfo(); + PropertyInfo currentDomain = appdomainType.GetProperty("CurrentDomain", + BindingFlags.Public | BindingFlags.Static); + EventInfo unhandledException = appdomainType.GetDeclaredEvent("UnhandledException"); + object appdomain = currentDomain.GetValue(null, null); + MethodInfo handlerInfo = typeof(AssemblyManager).GetTypeInfo().GetDeclaredMethod("UnhandledExceptionHandler"); + Delegate handler = handlerInfo.CreateDelegate(unhandledException.EventHandlerType); + var addMethod = unhandledException.GetAddMethod(true); + addMethod.Invoke(appdomain, new[] {handler}); + CurrentAssemblyLoaderContext = new AssemblyLoader(); if (!string.IsNullOrEmpty(preloadDirectory))