Repository navigation
Description
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
EnableNullableReferenceTypesoption of the DevWinUI template wizard) sees every DevWinUI API as nullable-oblivious. It gets no warning when it passesnullwhere the library does not accept it, or when it dereferences a result that can benull. - 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): anullliteral for a parameter, field or argument that is not annotated, for exampleCompositionEasingFunction easing = null.CS8618(396): a field or property that the constructor does not set, for example a template part or a DTO property such asUpdateInfo.TargetCommitish.CS8601,CS8600,CS8603andCS8604(885 together): a possiblenullthat flows into a non-nullable variable, return value or argument.CS8622(131): an event handler declared withobject senderfor a delegate whose sender isobject?, such asStoryboard.CompletedorDispatcherTimer.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:
DevWinUI.Shader,DevWinUI.SourceGeneratorandDevWinUI.ContextMenu(40 warnings together): set<Nullable>enable</Nullable>in the project files and fix the warnings.DevWinUI.Base.DevWinUI, split by folder (Controls/Native,Controls/Ported,Controls/Win2DAndCompositionand the rest) if one PR is too large to review.- Remove
CS8632fromNoWarnonce 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
ghost1372 commentedon Nov 15, 2026
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.
ghost1372 commentedon Nov 17, 2026
@xperiandri i enabled SourceGenerator, ContextMenu, Shaders and DevWinUI.Base, i am working on DevWinUI Folder by folder
Enable SourceGenerator nullable #233
Enable ContextMenu nullable #233
Enable Shaders nullable #233
enable nullable in DevWinUI.Base #233
Enable nullable in DevWinUI #233
Fix nullable warnings in DevWinUI #233
Fix nullable warnings in DevWinUI #233
Fix nullable Warnings in DevWinUI.Gallery #233
ghost1372 commentedon Nov 20, 2026
Done