Skip to content

[API Compat] CP0008 false positive for generic interfaces where the type argument is internal #45995

Open
@bitbonk

Description

@bitbonk

Describe the bug

When a public class implements a public generic interface but the generic type argument provided is internal a CP0008 validation error is raised when we make changes on the internal type.
I don't think the error should be raised as I can see no way how this could be binary or source incompatible.

To Reproduce

  1. Create nuget package with version 1.0.0 with the following code
    public class MyClass : IMyInterface<Foo>
    {
    }
    
    public interface IMyInterface<T>
    {
    }
    
    internal record Foo;
  2. Enable package validation for the package in the csproj
    <PropertyGroup>
      <!-- ... -->
      <EnablePackageValidation>true</EnablePackageValidation>
      <PackageValidationBaselineVersion>1.0.0</PackageValidationBaselineVersion>
    </PropertyGroup>
  3. Rename the internal (!) record Foo to Bar so that there is now the following code
    public class MyClass : IMyInterface<Bar>
    {
    }
    
    public interface IMyInterface<T>
    {
    }
    
    internal record Bar;
  4. Increment the package version to 1.1.0 and run dotnet pack

Actual Result

The following error occurs:

Microsoft.NET.ApiCompat.ValidatePackage.targets(39,5): Error  : API compatibility errors between 'lib/net6.0/AdventureWorks.Client.dll' (C:\Users\bitbonk\.nuget\packages\adventureworks.client\1.0.0\adventureworks.client.1.0.0.nupkg) and 'lib/net6.0/AdventureWorks.Client.dll' (C:\source\AdventureWorks.Client\AdventureWorks.Client\bin\Debug\AdventureWorks.Client.1.1.0.nupkg):
Microsoft.NET.ApiCompat.ValidatePackage.targets(39,5): Error CP0008 : Type 'A.MyClass' does not implement interface 'A.IMyInterface<A.Foo>' on lib/net6.0/AdventureWorks.Client.dll but it does on [Baseline] lib/net6.0/AdventureWorks.Client.dll

Expected Result

No error occurs.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions