#2220·serilog

Assembly.Load() no longer works for unreferenced dlls in .NET 5+

Author: marner2Created Feb 5, 2026Updated Feb 26, 2026
Labelsdiscussion

Description .NET 5+ doesn't allow Assembly.Load() to reference assemblies that were not present at compile time, and when one is attempted to be loaded, it throws an "Assembly Not Found" exception even though the dll is in fact in the correct spot.

See dotnet runtime issue 62522 for the change explanation.

Reproduction

  • Add a console sink dll to the application directory that is not referenced by the project
  • Reference it with configuration (for example):
var configuration = new LoggerConfiguration()
                .ReadFrom.KeyValuePairs(new Dictionary<string, string> {
                    {"using:1", "Serilog.Sinks.Console"},
                    { "write-to:1", "Console" }
                });

Expected behavior I would expect the dynamic loading to work, or an error message about not supporting dynamic loading in .NET 5+.

Relevant package, tooling and runtime versions Serilog 4.2.0 .NET 8.0 Windows 11 NOT using AOT or Single file publishing.

Additional context See serilog-settings-configuration issue 466 for a similar issue. Theirs is worse since they go searching through the directory and try loading all dlls with the word "serilog" in them, which causes it to break even without the key value pairs present.

I imagine changing the relevant line in KeyValuePairSettings to instead use Assembly.LoadFrom() with some basic tracking of the directory would work.