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.

Build fails with CS0263 when a partial class derived from a generic type is defined across different nullable contexts

See original GitHub issue

Related 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:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
RikkiGibsoncommented, Aug 24, 2021

I wrote up the following document for the purpose of LDM discussion. dotnet/csharplang#5107

2reactions
RikkiGibsoncommented, Aug 10, 2021

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compiler Error CS0263
Partial declarations of 'type' must not specify different base classes. When defining a type in partial declarations, specify the same base ...
Read more >
c# - generic class using nullable property of generic type
I created a custom Nullable<T> type with an implicit conversion from ... I can use almost the same syntax in construction of GenericClass<....
Read more >
C# 10.0 improves handling of nullable references in ...
The generic case, before nullable reference types. IComparable was introduced before generics, which is why the argument is of type object .
Read more >
C# Compiler Error Codes CS0001 to CS0500
Error Code Type Error/Warning Description CS0006 Error Metadata file '' could not be found CS0009 Fatal Metadata file '' could not be opened — CS0016 Error...
Read more >
Fighting with nullable reference types in Razor Pages
In this post I discuss C#'s nullable reference types in the context of Razor Pages, why they don't play nicely together and how...
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