dotnet / dotnet/sdk

APICompat doesn't detect the addition of `required` on a public C# property as breaking

Open
#55,860 0 comments 0 reactions 0 assignees View on GitHub
untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

The tool APICompat doesn't detect the addition of the keyword [`required`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/required) on a public property of a public class as a breaking change. But this addition will break compilation.

Adding args for strict mode and attributes-must-match doesn't trigger a difference detection.

### Steps to reproduce

see this repository for a script and projects that reproduce the issue: https://github.com/Thieum/dotnet-repro-required-apicompat

1. Create a reference object with a property
2. Generate the dll as a reference
3. Add required to the previous property
4. run `apicompat` on the reference and the new one, no difference will be detected. A consumer project that was using the first version will fail to build with the second one.

### Expected behavior

`apicompat` should detect the addition of `required` on a public property of a public object (in the IL it is expressed as an attribute?) and warn that it will break consumers of the assembly.

### Actual behavior

`apicompat` doesn't detect the addition of `required` on a public property of a public object, it will break compilation of consumers of the assembly.

### Is this a regression?

_No response_

### Are there any workarounds?

We are attempting to work around this issue by using NSwag and serialize to json the class, since it's our main end usage.

### dotnet --info output

```console

```

### IDE version

_No response_

### Other details

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked dotnet-repro-required-apicompat repository and run apicompat against its reference and updated assemblies. Trace how the tool compares public C# properties and attributes; done means the addition of required is reported as a breaking change, including when strict mode or attributes-must-match is used.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.