Build fails with CS0263 when a partial class derived from a generic type is defined across different nullable contexts
See original GitHub issueRelated to #38560
Version Used: version 3.8.0-dev (<developer build>) (Built from master a few minutes ago)
Steps to Reproduce:
Compile the following code:
class Base<T> { }
#nullable enable
partial class Derived : Base<object> { }
#nullable disable
partial class Derived : Base<object> { }
Expected Behavior:
The build should probably succeed. I’ve ran into this issue in a WPF project with nullable enabled (although the above code shows that this isn’t a WPF issue). Code generated from xaml files is marked as auto-generated
and is therefore has nullable disabled, which means that you can’t use xaml for classes with a generic base class (which unfortunately is quite common with ReactiveUI
, e.g. ReactiveWindow<ViewModel>
).
Actual Behavior:
<file>(4,15): error CS0263: Partial declarations of 'Derived' must not specify different base classes
I’ve also tried changing the base declaration to Base<object?>
in the nullable enable block, but that still gives the same error.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
I wrote up the following document for the purpose of LDM discussion. dotnet/csharplang#5107
It looks like the docs do a decent job of calling this out: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references#nullable-contexts
However, I am sympathetic that the existence of this doesn’t make it instantly easy to figure out why the heck it’s behaving this way 😃