Skip to content

[Feature]: Enable nullable reference types in the libraries #233

Closed

Description

@xperiandri

Feature proposal

Enable nullable reference types (<Nullable>enable</Nullable>) in the library projects: DevWinUI.Base, DevWinUI, DevWinUI.Shader, DevWinUI.ContextMenu and DevWinUI.SourceGenerator.

Today no library project sets <Nullable>, and CS8632 is suppressed in Directory.Build.props (since 6.4.1). The code already has ? annotations on reference types in several hundred places, and two files opt in with #nullable enable, but outside a nullable context the compiler ignores the annotations: they are not checked, and they are not written to the package metadata.

Why:

  • Consumers: an app with nullable reference types enabled (the default of the .NET SDK project templates, and the EnableNullableReferenceTypes option of the DevWinUI template wizard) sees every DevWinUI API as nullable-oblivious. It gets no warning when it passes null where the library does not accept it, or when it dereferences a result that can be null.
  • The library: the analysis finds possible null dereferences at compile time, for example a template part that is missing after OnApplyTemplate.
  • The existing annotations start to mean something instead of being ignored.

Measured impact

A Debug build of main (9873c0c, net11.0) with -p:Nullable=enable and no code changes reports 2,252 distinct nullable warnings in 370 files:

Project Warnings Files
DevWinUI 1,750 277
DevWinUI.Base 462 78
DevWinUI.ContextMenu 19 6
DevWinUI.SourceGenerator 12 5
DevWinUI.Shader 9 4

Most of them are mechanical:

  • CS8625 (556): a null literal for a parameter, field or argument that is not annotated, for example CompositionEasingFunction easing = null.
  • CS8618 (396): a field or property that the constructor does not set, for example a template part or a DTO property such as UpdateInfo.TargetCommitish.
  • CS8601, CS8600, CS8603 and CS8604 (885 together): a possible null that flows into a non-nullable variable, return value or argument.
  • CS8622 (131): an event handler declared with object sender for a delegate whose sender is object?, such as Storyboard.Completed or DispatcherTimer.Tick.

The warnings worth a closer look are the 174 CS8602, a possible null dereference.

Additional context

A possible plan, one PR per project to keep the reviews small:

  1. DevWinUI.Shader, DevWinUI.SourceGenerator and DevWinUI.ContextMenu (40 warnings together): set <Nullable>enable</Nullable> in the project files and fix the warnings.
  2. DevWinUI.Base.
  3. DevWinUI, split by folder (Controls/Native, Controls/Ported, Controls/Win2DAndComposition and the rest) if one PR is too large to review.
  4. Remove CS8632 from NoWarn once every library project is enabled.

If a project has too many warnings for one PR, <Nullable>annotations</Nullable> is an intermediate step without warnings. It publishes every unannotated reference type as non-nullable, though, so the public members that accept or return null have to be annotated before such a release.

Annotations change neither the runtime behavior nor the binary API. Consumers that enable nullable can get new warnings, which is the point.

I can prepare the PRs if you agree with the direction.

Activity

  1. added
    enhancement
    on Nov 15, 2026
  2. ghost1372 commented on Nov 15, 2026

    @ghost1372
    Owner

    Hi @xperiandri
    Thank you for your suggestion.
    I don't think there's any way around this, and we should finally take it into consideration. I've been quite busy adding new controls lately, and v11 is now finalized and will be released very soon, so I'll have to consider this for the next major/minor version.

    There are simply too many warnings, and fixing them all takes a lot of time. I think Claude could really help me with this and speed things up.

  3. ghost1372 commented on Nov 17, 2026

    @ghost1372
    Owner

    @xperiandri i enabled SourceGenerator, ContextMenu, Shaders and DevWinUI.Base, i am working on DevWinUI Folder by folder

  4. ghost1372 commented on Nov 20, 2026

    @ghost1372
    Owner

    Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions