Skip to content
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

Missing Microsoft.Extensions.Configuration.Abstractions.dll in .Net Framework 4.8 #586

Closed
JPasterkampRotec opened this issue May 11, 2022 · 7 comments
Labels
Milestone

Comments

@JPasterkampRotec
Copy link

JPasterkampRotec commented May 11, 2022

Type: Bug
NLog version: 4.7.15
NLog.Extensions.Logging version: 1.4.7
NLog.Web.AspNetCore version: (not used)
Platform: .Net Framework 4.8
Current NLog config:

var config = new LoggingConfiguration();
var logconsole = new ConsoleTarget("logconsole")
{
    Layout = "${time} ${pad:padding=-5:inner=${level:uppercase=true}}:  ${logger:shortName=true} - ${message} ${onexception:${newline}${exception:format=tostring}}"
};
config.AddRule(LogLevel.Trace, LogLevel.Fatal, logconsole);
LogManager.Configuration = config;
  • What is the current result?
    An exception when calling .AddNLog() for an ILoggingBuilder, because the Microsoft.Extensions.Configuration.Abstractions.dll is missing.

  • What is the expected result?
    I expected the Microsoft.Extensions.Configuration.Abstractions.dll to be included when installing NLog.Extensions.Logging in a .Net Framework 4.8 project.

  • Did you checked the Internal log?
    Not relevant I think.

  • Please post full exception details (message, stacktrace, inner exceptions)

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Extensions.Configuration.Abstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at NLog.Extensions.Logging.ConfigureExtensions.AddNLog(ILoggingBuilder factory, NLogProviderOptions options)
at MyLibrary.MyClass.<>c.b__13_1(ILoggingBuilder options)
at Microsoft.Extensions.DependencyInjection.LoggingServiceCollectionExtensions.AddLogging(IServiceCollection services, Action`1 configure)
at MyLibrary.MyClass.d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MyLibrary.ContainerBuilderExtensions.<>c__DisplayClass5_0.<b__0>d.MoveNext()

  • Are there any work arrounds? yes
    Manually installing the Microsoft.Extensions.Configuration.Abstractions.dll (5.0.0) package worked.
    However, I really don't like this workaround, because I'm shipping my code in question as a NuGet package; anyone installing the NuGet package would have to manually install this missing dll.

  • Is there a version in which it did worked?
    Not that I know of.

  • Can you help us by writing a unit test?
    No, but I can show you what I'm doing, which is attaching NLog to a SignalR client:

var connection = new HubConnectionBuilder()
    .WithUrl(HubEndpoint, options =>
    {
        options.AccessTokenProvider = GetAuthenticationToken;
    })
    .ConfigureLogging(options =>
    {
        options.AddNLog(); // The call that throws the exception
    })
    .WithAutomaticReconnect()
    .Build();

You can simply test it by:

  1. Installing NLog.Extensions.Logging in a .Net framework 4.8 console application.
  2. Build/run the project.
  3. Check the build folder (bin/Debug) and you will see there is no Microsoft.Extensions.Configuration.Abstractions.dll
@snakefoot
Copy link
Contributor

I'm guessing you have become used to .NET Core development, where transitive-nuget-dependencies just works, and no longer getting bitten by strong-version-assembly-issues.

For .NET Framework projects then transitive-nuget-dependencies can work automatically if changing to the new csproj-format where nuget-packages are included with <packagereference>. But if using the old csproj-format then you need to add this setting:

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

For any strong-version-assembly-issues, then your only friend is the binding-redirections. See also https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions and https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection

@JPasterkampRotec
Copy link
Author

JPasterkampRotec commented May 12, 2022

My projects are already using the PackageReferences strategy, so that's not the problem.
I've been looking at the NLog.Extensions.Logging csproj and I might've found the issue.

The net461 should also have Microsoft.Extensions.Configuration.Abstractions as a PackageReference right?

  <ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
    <PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.0.0" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.5' ">
    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.0.0" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
    <PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
    <PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
    <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
  </ItemGroup>

@snakefoot
Copy link
Contributor

@JPasterkampRotec
Copy link
Author

Microsoft.Extensions.Logging-nuget-package depends on Microsoft.Extensions.Logging.Abstractions

Microsoft.Extensions.Configuration.Abstractions is not the same as Microsoft.Extensions.Logging.Abstractions

@snakefoot
Copy link
Contributor

Microsoft.Extensions.Logging-nuget-package depends on Microsoft.Extensions.Configuration.Binder that depends on Microsoft.Extensions.Configuration.Abstractions

But I guess Microsoft have changed it so newer versions of Microsoft.Extensions.Logging doesn't have that dependency.

@snakefoot
Copy link
Contributor

Created #590 to reduce the pain from the change in Microsoft.Extensions.Logging-dependency-tree

@snakefoot
Copy link
Contributor

NLog 5.0 has now been released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants