-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConfigurationReader is attempting to load assemblies not associated with the project but found by the DllScanningAssemblyLoader #406
Comments
Thanks for the note. Dealing with Your best bet is to use the |
As a work around I've just added references to all sinks we are using to all projects. But I think it clearly should be considered to not do a file based lookup of dlls, as there is the potential, that they can't be loaded. The DllScanningAssemblyFinder will only work on the classic .NET framework and will break newer applications, if it finds a file not referenced by the project. |
You should probably do what @nblumhardt suggested instead, i.e. passing explicit assemblies to the var configurationAssemblies = new[]
{
typeof(ILogger).Assembly, // Serilog
typeof(SerilogExpression).Assembly, // Serilog.Expressions
typeof(ProcessLoggerConfigurationExtensions).Assembly, // Serilog.Enrichers.Process
typeof(ThreadLoggerConfigurationExtensions).Assembly, // Serilog.Enrichers.Thread
typeof(Log4NetTextFormatter).Assembly, // Serilog.Formatting.Log4Net
typeof(ConsoleLoggerConfigurationExtensions).Assembly, // Serilog.Sinks.Console
typeof(LoggerConfigurationEventLogExtensions).Assembly, // Serilog.Sinks.EventLog
typeof(FileLoggerConfigurationExtensions).Assembly, // Serilog.Sinks.File
typeof(NotepadLoggerConfigurationExtensions).Assembly, // Serilog.Sinks.Notepad
typeof(UdpClientFactory).Assembly, // Serilog.Sinks.Udp
};
var readerOptions = new ConfigurationReaderOptions(configurationAssemblies);
configuration.ReadFrom.Configuration(context.Configuration, readerOptions);
This is exactly what happens when you explicitly pass assemblies as in the example above: no file based lookup occurs at all. |
Of course I can do that, but isn't that simply a work around? As I see it, currently the ConfigurationReader is able to execute a code path which might lead to a crash due to an unsupported combination of file based lookup of dlls and the later Assembly.Load. Further more, somebody unaware of the fact that the assemblies have been defined manually, could have a hard time adding a new sink because he first must find this declaration and extend it. No blocker but imho not intuitiv too. |
Does specifying a list of assemblies disable the dynamic lookup of dll's? I'm running into this issue: Hosting net8 app on IIS. Reproducing this locally (just pasting the Serilog.UI files in the output) gives me a In my case it took a long time to figure out why it was loading Serilog.UI after i removed the reference since it was not used in a Also i'm now puzzled why it fails to load the DLL, because it should load just fine, its in the output directory it was the right version etc. Anyhow in my case the 'fix' should be to just remove the extra dll's - but this seems like it could happen again in the future so i thought i'd bring it up. |
@sommmen: Because Assembly.Load doesn't load files from the disk which are not referenced by the project in anyway, for security reasons. And that's the issue with serilogy, because it uses a file based lookup and attempting to load the found files, if referenced or not. |
I think I stumbled on a closely related problem. In a .net 4.8 application, I get an unhandled exception on startup because it loads (or attempts to load) some DLL. But the problem is, it fails one one specific system and works just fine elsewhere. As you might guess it's the customer's system. I don't have regular access to the system, but I got this from the ETW application log:
So it seems that on this one system, the logic fails even before .net 5. My wild guess is some 32 Bit 3rd-party DLL in the GAC or somewhere found by the Auto resolver. I will try the workarounds suggested here next me I get the chance. It would be nice if this behaviour could be disabled in the config file though. |
I've found following bug:
The DllScanningAssemlyFinder is scanning the Application's directory for dlls containing .serilog in its name. Later on the ConfigurationReader attempts to load the results with the Assembly.Load function.
Unfortunately Assembly.Load only works with assemblies referenced by the application and does no actual disk lookup. So a user attempted to add a new sink to an application, copying manually the sink's dll into the folder will have no success, as the Dll scanner will find the dll but the ConfigurationReader is unable to load it and the application will crash with a FileNotFoundException.
The behavior of Assembly.Load has changed since in the .NET5 framework: dotnet/runtime#62522
See my other ticket here, how this error will sho up: #407
The text was updated successfully, but these errors were encountered: