enableing nullable checking project wide breaks generic usercontrols (CS0263)
See original GitHub issue- .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:
namespace WpfApp1.Tests {
public class GridBase : UserControl { }
public class CCCCCC<T> : GridBase where T : class { }
public class testclass { }
public partial class UserControl1 : CCCCCC<testclass> {
public UserControl1() {
InitializeComponent();
}
}
}
<local:CCCCCC x:Class="WpfApp1.Tests.UserControl1"
x:TypeArguments="local:testclass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1.Tests"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<DataGrid Background="BlueViolet">
</DataGrid>
</local:CCCCCC>
This UserControl compiles fine with the following project settings:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<!--<Nullable>enable</Nullable>-->
</PropertyGroup>
</Project>
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
).
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Update your codebase to use nullable reference types
Nullable reference types enable you to declare if variables of a reference type should or shouldn't be assigned a null value.
Read more >Disable null validation in ASP.Net 6 project
NET 6 they are enabled by default. To turn it off, in your csproj file add this line <Nullable>disable</Nullable> . For example:
Read more >Migrating to .NET 6 : r/dotnet
NET 5 project, I decided to update to the .NET 6 framework. However, the proj file enables nullable, which has lead to over...
Read more >Nullable Reference types in C# – Best practices
In this tutorial, I look at the state of the Nullable Reference Types feature in C#, one year after its initial release.
Read more >C# 10.0 improves handling of nullable references in ...
This expresses ordered comparison, enabling you to determine whether one value is less then, equal to, or greater than some other value.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
also: a workaround is:
@kkirkfield compiles fine for me one 7.0.100-rc.1.22431.12 and VS 17.4 preview. As noted above, this is not a WPF but Roslyn issue. Note the https://github.com/dotnet/roslyn/issues/63490 is on 17.4 milestone.