# Description Nullable reference types are now enabled once, in `common.props`, and every project in the repository builds warning-clean with them. **Configuration** - `<Nullable>enable</Nullable>` lives in `common.props`. All per-project `<Nullable>` settings are removed: 178 project files (enable, annotations, and the `disable` in the three Aot test projects). - 419 per-file `#nullable enable`/`restore` directives and the 4 `#nullable disable` directives are removed. - Kept on purpose: - The 5 `<auto-generated>` schema files (`UANodeSet.cs`, `UA Type Dictionary.cs`, `OPCBinarySchema.cs`, `SecuredApplication.cs`, `PInvokeHelper.cs`) keep `#nullable enable`. The compiler ignores the project setting in generated code, so the directive is required there. - `tests/Opc.Ua.Interop.LegacyPeer` keeps `disable`. It builds against the 1.5.378 packages and does not import the repository props. - `docs/DeveloperGuide.md` and `.github/copilot-instructions.md` now describe the central setting. **Migration** (the 43 unset and 13 annotations-only projects, roughly 10k diagnostics) - **Production code: annotated at the declarations.** Covers `tools/Opc.Ua.SourceGeneration.Core`, `src/Opc.Ua.Lds.Server` and the LDS sample. - Members, parameters and returns are nullable where null actually flows. - Null-check helpers carry `[NotNullWhen]` (`IsNull`, `IsValidXmlName`, `IsMethodTypeDesign`). - `CoreUtils.Format`, `Utils.Format`, `ITemplateWriter.WriteLine` take `params object?[]`. `Template.AddReplacement` takes `string?` (rendering already skips null replacements). - `IRegisteredServerStore.RegisterAsync` returns `Task<RegistrationEntry?>`: it returns null when a registration is removed. - Dereferences backed by an invariant (for example, the validated model) use `!`, so runtime behaviour is unchanged. - **Behavioural changes in production code** (small, deliberate): - `NodeSetToModelDesign` throws `InvalidOperationException` when the file is not a NodeSet. Before, it threw a NullReferenceException on the next line. - `ModelDesignValidator` starts its lookup tables empty instead of null. A redundant `if (m_nodes == null) return;` guard is gone. - **Test code: minimal annotations.** - `?` on values that can be null, `!` where the test asserts non-null. - `= null!` for fixture members assigned in SetUp. - `TryGetStructure<T>(out T? x)` where the inferred `T?` broke the `IEncodeable` constraint. - A few redundant `== null` checks on structs (`NodeId`, `ArrayOf<T>`) folded into the adjacent `IsNull`/`Count` checks. **Notes for reviewers** - The diff is large (~1,500 files) but almost entirely mechanical: `?`, `!` and directive removal. The non-annotation changes are listed above. - Known follow-up, not done here: `IModelDesign.Namespaces/TargetNamespace/NamespaceUris` stay non-nullable even though the validator returns null before it loads a dictionary. Making them nullable would ripple through every generator call site. ## Related Issues - Fixes #4439 ## Checklist - [ ] I have signed the [CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf) and read the [CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md) doc. - [ ] I have added tests that prove my fix is effective or that my feature works and increased code coverage. - [x] I have added all necessary documentation. - [x] I have verified that my changes do not introduce (new) build or analyzer warnings. - [ ] I ran **all** tests locally using the **UA.slnx** solution against at least .net **framework** and .net **10**, and all passed. - [ ] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [ ] I have addressed **all** PR feedback received. The "no new warnings" box covers net10.0 and net48: full non-incremental builds of `UA.slnx`, `tools/SourceGeneration.slnx`, `tools/MigrationAnalyzer.slnx` and the Aot test projects finished with 0 warnings and 0 errors under the repository's warnings-as-errors settings. net9.0 and net8.0 also had no nullable diagnostics, but they were not rebuilt after the final fixes. Tests have not been run locally yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Coverage NodeSet test harness (issue #4251)
This directory contains a purpose-authored "kitchen-sink" NodeSet2
(Assets/Opc.Ua.CoverageTest.NodeSet2.xml) plus a small dependent secondary
model (Assets/Opc.Ua.CoverageTestSecondary.NodeSet2.xml) that deliberately flips
a broad set of the knobs defined by UANodeSet.xsd, and a data-driven assertion
battery that runs the same checks against the model loaded through three
independent pipelines:
- Source-generation (hand-written manager) — the XML is consumed at compile
time via
<AdditionalFiles ModelSourceGeneratorPrefix="Opc.Ua.CoverageTest">inOpc.Ua.Server.Tests.csproj. The generatedAddOpcUaCoverageTest(context)extension composes the predefined nodes inside the hand-writtenCoverageTestNodeManager : CustomNodeManager2(CoverageTestSourceGenServer). Every authored node materialises as its generatedNodeStatesubclass. - Runtime import — the identical XML is embedded as a resource and imported
at startup through
RuntimeNodeSetNodeManagerFactory/AddRuntimeNodeSet(CoverageTestRuntimeServer). - Source-generation (generated fluent manager) — a
[NodeManager]-attributed partial (CoverageTestFluentNodeManager) makes the generator emit the entireFluentNodeManagerBasemanager, factory and typed fluent-builder surface (CoverageTestFluentGenServer).
Each server is started for real (ServerFixture<T> + ReferenceServer), and the
assertion battery is executed once per server, then a cross-pipeline equivalence
fixture asserts the three address spaces agree.
Files
| File | Purpose |
|---|---|
Assets/Opc.Ua.CoverageTest.NodeSet2.xml |
The primary kitchen-sink model. |
Assets/Opc.Ua.CoverageTest.NodeSet2.csv |
Matching SymbolicName/Id/NodeClass table for byte-stable ids. |
Assets/Opc.Ua.CoverageTestSecondary.NodeSet2.xml |
A dependent second-namespace model (cross-namespace references). |
CoverageTestCatalogue.cs |
The expected node + reference catalogue (drives the data-driven tests). |
CoverageTestSourceGenServer.cs |
Source-generation host (CoverageTestNodeManager), owns both namespaces. |
CoverageTestRuntimeServer.cs |
Runtime-import host (two dependency-sorted sources). |
CoverageTestFluentNodeManager.cs / CoverageTestSecondaryFluentNodeManager.cs |
[NodeManager] partials for the generated fluent managers. |
CoverageTestFluentGenServer.cs |
Generated-fluent-manager host. |
CoverageNodeSetAssertionsBase.cs |
The shared, data-driven assertion battery (generic over the server type). |
CoverageTestAssertionsTests.cs |
Concrete fixtures binding the battery to each pipeline. |
CoverageTestEquivalenceTests.cs |
Cross-pipeline structural equivalence fixture (all three servers). |
What is exercised
- Every node class (
UAReferenceType,UADataType,UAObjectType,UAVariableType,UAObject,UAVariable,UAMethod,UAView). - Every
Definitionshape (Enumeration, OptionSet, Structure, Structure with an optional field, Union, an abstract structure, non-defaultPurpose). - Scalar, array and matrix variable value shapes.
- A deep, branching instance tree (depth 4, two branches) navigated child-by-child.
- NamespaceMetadata publication — the
NamespaceMetadataObject exists for both namespaces (all pipelines) and, for the two source-generated pipelines, surfaces the model'sNamespaceVersion(1.2.3) andNamespacePublicationDate(2024-06-01). The runtime-import pipeline carries noModelDependencyassembly attribute, so it only asserts the Object and itsNamespaceUri. - Deterministic method call — invoking the authored
AddNumbersmethod with no bound handler returnsBadNotImplementedand yields the identical status on every call. - A second (dependent) namespace with cross-namespace
HasTypeDefinition,HasSubtypeandHasComponentreferences, hosted in all three pipelines. - Custom reference types: hierarchical/asymmetric (with
InverseName), symmetric, an abstract type with a concrete subtype, plus inverse authoring. - Non-default common/instance/variable/method/view attributes, all five
HasModellingRuletargets, and a broad set of reference relations (HasComponent,HasProperty,HasOrderedComponent,HasSubtype,HasTypeDefinition,HasEncoding,HasEventSource,HasCondition,HasInterface,GeneratesEvent/AlwaysGeneratesEvent,FromState/ToState/HasCause/HasEffect,HasTrueSubState/HasFalseSubState, and the custom reference types).
Known pipeline differences (intentionally not asserted for equivalence)
The reference catalogue deliberately excludes edges where the two pipelines legitimately differ, so the equivalence fixture stays strict on everything else:
- Type dictionaries /
DataTypeDescriptionnodes are not authored. The source generator regenerates the binary/XML schema from theDataTypeDefinitions rather than emittingDataTypeDictionarynodes into the address space, so hand-authored dictionary nodes would diverge. As a consequence theHasDescriptionandHasDictionaryEntryrelations are not covered here. - Duplicate hierarchical references to the same child (for example a
HasComponentalongside a custom hierarchical reference, orHasNotifieralongsideHasEventSource) and aView'sOrganizesedges to already-parented nodes are represented differently by the two importers, so those specific edges are not asserted for equivalence. - Runtime structure stand-ins — the runtime complex-type loader registers
the enumeration and option-set stand-ins for this multi-type model but not the
structure stand-ins; the structure definitions are validated directly via
the
DataTypeDefinitionround-trip instead.
Related generator and product fixes
Authoring this model surfaced two latent source-generator issues and one product bug, all fixed:
- A top-level
<ServerUris>table crashedNodeSetToModelDesign(StringTable.Append(null)for the reserved local-server slot). The guard is intools/Opc.Ua.SourceGeneration.Core/Schema/NodeSetToModelDesign.csand is regression-tested byNodesetServerUrisTestsinOpc.Ua.SourceGeneration.Tests. - A model with more than one structure (hence more than one
Default Binaryencoding) made the generated typed fluent builder emit colliding accessors, becauseDataTypeEncodingobjects hang off theirDataTypeand surfaced as parent-less "root" instances sharing the reservedDefaultBinary/DefaultXml/DefaultJsonsymbolic names.FluentBuilderGenerator.GetTopLevelInstancesnow skipsDataTypeEncodingobjects (they are encoding metadata, never fluent-wired). NamespaceMetadataPublishernever stamped a model's publication date because the "unset" guard compared againstDateTime.MinValue(0001-01-01) while an unsetNamespacePublicationDatedefaults to the OPC UA epoch (1601-01-01); it now usesDateTimeUtc.IsNull. It also only discovered theModelDependencyattribute through a node manager's sync facade, which is a framework wrapper for async-native (fluent) managers; it now scans both the async manager's and its sync facade's assemblies so the fluent pipeline publishes version metadata too.