Azure / Azure/azure-functions-host
Improve logging for assembly load failures
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 36
Description
Troubleshooting issues in production where an assembly failed to load is really hard. We've had a number of reported cases where this was happening in a transient manner i.e. the issue wasn't with how the application was authored and was not reproducible.
It appears that in some cases, you can get some pretty useful troubleshooting info when an assembly fails to load. For example, observe the following C# .NET 4.7 program and its output:
```csharp
static void Main(string[] args)
{
try
{
var assemblyC = "ClassLibraryC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
Assembly.Load(assemblyC);
}
catch(Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
```
```
System.IO.FileNotFoundException: Could not load file or assembly 'ClassLibraryC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'ClassLibraryC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence
=== Pre-bind state information ===
LOG: DisplayName = ClassLibraryC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///D:/code/temp/AssemblyLoadSandbox/SimpleAssemblyLoadFailure/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : SimpleAssemblyLoadFailure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\code\temp\AssemblyLoadSandbox\SimpleAssemblyLoadFailure\bin\Debug\SimpleAssemblyLoadFailure.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///D:/code/temp/AssemblyLoadSandbox/SimpleAssemblyLoadFailure/bin/Debug/ClassLibraryC.DLL.
LOG: Attempting download of new URL file:///D:/code/temp/AssemblyLoadSandbox/SimpleAssemblyLoadFailure/bin/Debug/ClassLibraryC/ClassLibraryC.DLL.
LOG: Attempting download of new URL file:///D:/code/temp/AssemblyLoadSandbox/SimpleAssemblyLoadFailure/bin/Debug/ClassLibraryC.EXE.
LOG: Attempting download of new URL file:///D:/code/temp/AssemblyLoadSandbox/SimpleAssemblyLoadFailure/bin/Debug/ClassLibraryC/ClassLibraryC.EXE.
```
Can we get the second part of that output into our log somehow? It would make a huge difference for investigating these issues. I should note that I do not have fusion logs turned on.
Contributor guide
Assessment
This issue has not been assessed yet.