}
}
+ 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))