From d1996eaf33451d4c9ceb207247c8c2f33107ab09 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Tue, 15 Nov 2016 15:49:52 +0900 Subject: Add Unhandled Exception handler for Dlog output Add temporarily implmentation until become Appdomain on API Change-Id: I6c622d701d94cf3cc29262e066a490f102cfd46b --- .../Tizen.Runtime.Coreclr/AssemblyManager.cs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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)) -- cgit v1.2.3