adams85 / po

A library for reading and writing Gettext PO files.
MIT License
61 stars 16 forks source link

Package Version Conflict #16

Closed woutervanranst closed 2 years ago

woutervanranst commented 2 years ago
public static int Main(string[] args)
{
    var services = new ServiceCollection()
        .AddLogging(builder =>
        {
            // Add File Logging
            builder.AddFile(o => o.RootPath = AppContext.BaseDirectory);
        });

    var x = services.BuildServiceProvider().GetRequiredService<ILoggerFactory>();

    return 0;
}

with csproj

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <AssemblyName>arius</AssemblyName>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Karambolo.Extensions.Logging.File" Version="3.2.1" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
        <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
    </ItemGroup>

    <ItemGroup>
        <None Update="appsettings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>

</Project>

yields this exception on the GetRequiredService

System.MethodAccessException: 'Attempt by method 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigurationFactory.GetConfiguration(System.Type)' to access method 'Microsoft.Extensions.Logging.ProviderAliasUtilities.GetAlias(System.Type)' failed.'

When changing the csproj file to the following (note the Hosting io. Configuration.Json, DependencyInjection, Logging) and cleaning the solution, it works as expected

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <AssemblyName>arius</AssemblyName>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Karambolo.Extensions.Logging.File" Version="3.2.1" />
        <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
    </ItemGroup>

    <ItemGroup>
        <None Update="appsettings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>

</Project>
woutervanranst commented 2 years ago

Closing this issue - created this in the wrong repo. Sorry.

See https://github.com/adams85/filelogger/issues/19