dotnet / dotnet/wpf

enableing nullable checking project wide breaks generic usercontrols (CS0263)

Open
#5,695 7 comments 0 reactions 1 assignee Claimed by @ayushverma-ms View on GitHub
Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: 5.0.403 bf9d168ac2 SDK (core 3.1)
* Windows version: Win10 | 20H2 Build 19042.1052
* Does the bug reproduce also in WPF for .NET Framework 4.8?: have not checked

**Problem description:**
Assume this minimal test project:
```csharp
namespace WpfApp1.Tests {
public class GridBase : UserControl { }

public class CCCCCC : GridBase where T : class { }

public class testclass { }

public partial class UserControl1 : CCCCCC {
public UserControl1() {
InitializeComponent();
}
}
}
```
```xml


```

This UserControl compiles fine with the following project settings:
``` xml


WinExe
netcoreapp3.1
true

```
but once you uncomment the project wide nullable setting, the whole project no longer compiles and the following error occurs;
`CS0263 Partial declarations of 'UserControl1' must not specify different base classes WpfApp1 [...]\WpfApp1\UserControl1.xaml.cs 18`

This however is a different error message from the one you actually get when using two different base classes for your xaml and c# side (usually you get `Base class of 'WpfApp1.Tests.UserControl1' differs from declared in other parts`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.