Pārlūkot izejas kodu

Add more error information to TypeLoader

ManlyMarco 6 gadi atpakaļ
vecāks
revīzija
5179507da0
1 mainītis faili ar 22 papildinājumiem un 1 dzēšanām
  1. 22 1
      BepInEx/Bootstrap/TypeLoader.cs

+ 22 - 1
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();
+        }
     }
 }