question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DependencyContextAssemblyFinder.FindAssembliesContainingName Throws on GetDefaultAssemblyNames

See original GitHub issue

Okay 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:closed
  • Created 4 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
skomis-mmcommented, Aug 21, 2019

@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.

1reaction
skomis-mmcommented, Aug 16, 2019

@CreepyGnome dev. Master is for stable releases

Read more comments on GitHub >

github_iconTop Results From Across the Web

Untitled
Getdefaultassemblynames Web26 Sep 2016 · public CommunicationsManager () { var assemblies = from name in DependencyContext.Default.
Read more >
DependencyContext.Load(Assembly) Method
Loads the dependency context for the specified assembly.
Read more >
DependencyContext Class
Gets the Type of the current instance. (Inherited from Object). Load(Assembly). Loads the dependency context for the specified assembly. MemberwiseClone ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found