Closed woutervanranst closed 2 years ago
Please read this part of the docs carefully. You've been bitten by this:
The package depends on some framework libraries and references the lowest possible versions of these depencencies (e.g. Microsoft.Extensions.Logging.Configuration 3.0.0 in the case of .NET Standard 2.1 target framework). These versions may not (mostly do not) align with the version of your application's target platform since that may be a newer patch, minor (or even major) version (e.g. .NET Core 3.1.11).
You're referencing Microsoft.Extensions.Logging
6.0.0 in your csproj. Either don't do that (as Karambolo.Extensions.Logging.File
already does, just version 3.0.0) or explicitly reference the dependencies of Karambolo.Extensions.Logging.File
with version 6.0.0.
Otherwise you'll end up with mixed versions of dependencies which leads to MethodAccessException
as apparently the logger internals have breaking changes between 3.0.0 and 6.0.0.
Bottom line: add the following package references to your csproj and you're good to go.
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="6.0.0" />
Hm; RTFM you say? ;)
Thanks -- that worked. Was hoping you'd release a new version on the back of the net6 release? :)
Unfortunately adding other target frameworks like .NET 6 wouldn't really help. Since the base metapackage Microsoft.NETCore.App doesn't references the *Microsoft.Extensions.* packages, only the Microsoft.AspNetCore.App* does, I'd be compelled to also add a FrameworkReference
to the latter. The problem is that not all .NET projects are ASP.NET Core applications (there are e.g. console and desktop apps) and referencing the whole ASP.NET Core enchilada in such projects seems wrong.
Another option would be to make releases with updated dependency versions every time MS release a new version (even a patch version) of the runtime. But this would be kinda nonsensical too.
So I'm afraid currently there's no better solution than explicit references in non-ASP.NET Core projects. Anyway, I've updated the installation instructions in the docs to make this a bit clearer.
with csproj
yields this exception on the
GetRequiredService
When changing the csproj file to the following (note the Hosting io. Configuration.Json, DependencyInjection, Logging) and cleaning the solution, it works as expected