Skip to content

Expected diamond-depndency conflict if multi-versions referenced and third-party component does not update - does not affect HttpClientFactory [ System.TypeLoadException when referencing both Polly 7 and transitive Polly 6 ] #615

@altso

Description

@altso

Assuming a solution with the following project/code structure:

PollySeven.MyHttpClient depends on Microsoft.Extensions.Http.Polly (which depends on Polly v6).
PollySeven.MyHttpClient uses RetryAsync() extension method to register MyService.
PollySeven depends on PollySeven.MyHttpClient and Polly v7.
PollySeven uses MyService.

image

PollySeven

public static void Main(string[] args)
{
    var services = new ServiceCollection();
    services.AddMyServices();

    ServiceProvider provider = services.BuildServiceProvider(true);

    var service = provider.GetRequiredService<MyService>();

    // System.TypeLoadException:
    // 'Could not load type 'Polly.RetrySyntaxAsync' from assembly
    // 'Polly, Version=7.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc'.'
}

PollySeven.MyHttpClient

public static IServiceCollection AddMyServices(this IServiceCollection services)
{
    services.AddHttpClient<MyService>()
        .AddTransientHttpErrorPolicy(p => p.RetryAsync());
    return services;
}

When the application runs, I get System.TypeLoadException.

The root cause of this issue might be similar to #611.

Expected behavior:
Code executes successfully.

Actual behaviour:

System.TypeLoadException is thrown:

Could not load type 'Polly.RetrySyntaxAsync' from assembly
'Polly, Version=7.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc'.

Steps / Code to reproduce the problem:

Example repo: https://github.com/altso/PollySeven

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions