DependencyContextAssemblyFinder.FindAssembliesContainingName Throws on GetDefaultAssemblyNames
See original GitHub issueOkay so this is regarding the following class and its method FindAssembliesContainingName
:
serilog-settings-configuration/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DependencyContextAssemblyFinder.cs
This all started when implementing Serilog with my ASP.NET Core Web API services and when I got to adding the JSON Configuration settings the .Configuration(Configuration)
extension method called as so new LoggerConfiguration() .ReadFrom.Configuration(Configuration)
it would throw a FileLoadException: The given assembly name or codebase was invalid.
I couldn’t figure out why as I have all the required Serilog dependencies from your readme, and I can get it working in a clean new API.NET Core Web API project, just not any of the real-world production projects.
I walked through the stack trace and found that it was in your DependencyContextAssemblyFinder.FindAssembliesContainingName
when it calls GetDefaultAssemblyNames when the Linq query is executed on the ToList() call.
If I remove the second from it doesn’t throw and when I compared what it is doing I am not sure why the second from is even there to guard against or what is gained with it.
For example here is the results returned from the default template project where it works as-is:
Serilog Serilog.AspNetCore Serilog.Enrichers.Environment Serilog.Enrichers.Thread Serilog.Extensions.Logging Serilog.Settings.Configuration Serilog.Sinks.Console Serilog.Sinks.File
And here are the results when you remove that second from in that project and in my production project where it would throw if it was there:
Serilog Serilog.AspNetCore Serilog.Enrichers.Environment Serilog.Enrichers.Thread Serilog.Extensions.Logging Serilog.Settings.Configuration Serilog.Sinks.Console Serilog.Sinks.File
As you can see they are 100% the same results so not sure what is the purpose or what is gained with the second from.
I would suggest that we change this:
public override IReadOnlyList<AssemblyName> FindAssembliesContainingName(string nameToFind)
{
var query = from library in _dependencyContext.RuntimeLibraries
from assemblyName in library.GetDefaultAssemblyNames(_dependencyContext)
where IsCaseInsensitiveMatch(assemblyName.Name, nameToFind)
select assemblyName;
return query.ToList().AsReadOnly();
}
To this:
public override IReadOnlyList<AssemblyName> FindAssembliesContainingName(string nameToFind)
{
var query = from library in _dependencyContext.RuntimeLibraries
where IsCaseInsensitiveMatch(library.Name, nameToFind)
select assemblyName;
return query.ToList().AsReadOnly();
}
I would be more than happy to make a PR for this just wanted to check to find out if I am missing something for this line of code from assemblyName in library.GetDefaultAssemblyNames(_dependencyContext)
before doing it. As this is a blocking issue for me on being able to use this NuGet package. I am not familiar enough with DependencyContext and the DependcyModel extensions to know how to provide my own instead of the default one that is being used. Your readme doesn’t touch on this except to state it uses it and that’s it.
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (8 by maintainers)
@CreepyGnome ,
The IDE test runner should be supported IMO, but I believe the last time it was tested before VS 2019 launch. I think the problem is with
15.0.0
Test SDK with VS 2019. But later versions of SDK are backward compatible as you pointed (e.g. 16.2.0 with VS2017)I think this change can be combined in single PR since its a tiny change (update
PackageReference
in the csproj) or it can be separate if you want so.@CreepyGnome dev. Master is for stable releases