question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
SaculRennorbcommented, Nov 15, 2021

also: a workaround is:

#nullable disable
  public partial class UserControl1 : CCCCCC<testclass> {
#nullable enable
1reaction
miloushcommented, Sep 23, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found