dotnet / dotnet/sdk

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

Open
#45,995 1 comment 0 reactions 1 assignee Claimed by @ViktorHofer View on GitHub
Area-ApiCompat
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### 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
```csharp
public class MyClass : IMyInterface
{
}

public interface IMyInterface
{
}

internal record Foo;
```
2. Enable package validation for the package in the csproj
```xml


true
1.0.0

```
3. Rename the internal (!) record `Foo` to `Bar` so that there is now the following code
```csharp
public class MyClass : IMyInterface
{
}

public interface IMyInterface
{
}

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' on lib/net6.0/AdventureWorks.Client.dll but it does on [Baseline] lib/net6.0/AdventureWorks.Client.dll
```

#### Expected Result

No error occurs.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.