From 5179507da03e23e1d013cdf921ef4c1d84d1a53f Mon Sep 17 00:00:00 2001 From: ManlyMarco Date: Sun, 25 Nov 2018 23:05:07 +0100 Subject: [PATCH] Add more error information to TypeLoader --- BepInEx/Bootstrap/TypeLoader.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/BepInEx/Bootstrap/TypeLoader.cs b/BepInEx/Bootstrap/TypeLoader.cs index c78a075..265001c 100644 --- a/BepInEx/Bootstrap/TypeLoader.cs +++ b/BepInEx/Bootstrap/TypeLoader.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Reflection; +using System.Text; using BepInEx.Logging; namespace BepInEx.Bootstrap @@ -36,13 +37,33 @@ namespace BepInEx.Bootstrap } } catch (BadImageFormatException) { } //unmanaged DLL - catch (ReflectionTypeLoadException) + catch (ReflectionTypeLoadException ex) { Logger.Log(LogLevel.Error, $"Could not load \"{Path.GetFileName(dll)}\" as a plugin!"); + Logger.Log(LogLevel.Debug, TypeLoadExceptionToString(ex)); } } return types; } + + private static string TypeLoadExceptionToString(ReflectionTypeLoadException ex) + { + StringBuilder sb = new StringBuilder(); + foreach (Exception exSub in ex.LoaderExceptions) + { + sb.AppendLine(exSub.Message); + if (exSub is FileNotFoundException exFileNotFound) + { + if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) + { + sb.AppendLine("Fusion Log:"); + sb.AppendLine(exFileNotFound.FusionLog); + } + } + sb.AppendLine(); + } + return sb.ToString(); + } } }