From 050316dc789b6a87895fc0ea32fdc59baef4747d Mon Sep 17 00:00:00 2001 From: Byron Mayne Date: Thu, 20 Jun 2024 20:45:54 -0400 Subject: [PATCH] Wrapped assembly loading in a try catch When as assembly was a reference only assembly it would throw an exception crashing the generator. Unfortunately there is not an easy way to scan for this. --- .../Templates/SourceGeneratorHoistBase.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/SourceGenerator.Foundations/Templates/SourceGeneratorHoistBase.cs b/src/SourceGenerator.Foundations/Templates/SourceGeneratorHoistBase.cs index f9c3ac8..cd985fa 100644 --- a/src/SourceGenerator.Foundations/Templates/SourceGeneratorHoistBase.cs +++ b/src/SourceGenerator.Foundations/Templates/SourceGeneratorHoistBase.cs @@ -46,6 +46,9 @@ static SourceGeneratorHoist() [ModuleInitializer] internal static void Initialize() { + System.Console.WriteLine("Console.WriteLine"); + System.Diagnostics.Debugger.Log(1, "whatever", "Deugger.Log"); + if(s_isInitialized) { return; @@ -153,12 +156,17 @@ private static bool TryExtractingAssembly(Assembly assembly, string resourceName loadedAssembly = null; if (TryGetResourceBytes(assembly, resourceName, out byte[]? assemblyBytes)) { + try + { #pragma warning disable RS1035 // Do not use APIs banned for analyzers - loadedAssembly = TryGetResourceBytes(assembly, Path.ChangeExtension(resourceName, ".pdb"), out byte[]? symbolBytes) - ? Assembly.Load(assemblyBytes, symbolBytes) - : Assembly.Load(assemblyBytes); + loadedAssembly = TryGetResourceBytes(assembly, Path.ChangeExtension(resourceName, ".pdb"), out byte[]? symbolBytes) + ? Assembly.Load(assemblyBytes, symbolBytes) + : Assembly.Load(assemblyBytes); #pragma warning restore RS1035 // Do not use APIs banned for analyzers - return true; + return true; + } + catch + {} } return false; }