Skip to content

Commit

Permalink
Wrapped assembly loading in a try catch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ByronMayne committed Jun 21, 2024
1 parent d81ca77 commit 050316d
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 050316d

Please sign in to comment.