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

Package Version Conflict #16

Closed
woutervanranst opened this issue Nov 20, 2021 · 1 comment
Closed

Package Version Conflict #16

woutervanranst opened this issue Nov 20, 2021 · 1 comment

Comments

@woutervanranst
Copy link

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
Copy link
Author

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

See adams85/filelogger#19

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

No branches or pull requests

1 participant