Files
Marc Schier 20d9d65a64 Fix generated configuration namespace resolution (#4019)
# Description

Fix source-generated configuration types whose explicit namespace
references constants emitted by the same generator pass. Roslyn cannot
resolve those constants while `[DataType]` attributes are analyzed, so
the generated XML codec silently fell back to `urn:memorybuffer` /
`urn:testdata` while the shipped configuration uses the model namespace
URIs.

This change:

- adds `MODELGEN021` to fail when an explicitly supplied
`[DataType.Namespace]` expression cannot be resolved;
- uses compile-time-available model namespace URIs for the MemoryBuffer
and TestData configuration types;
- restores production-shaped XML fixtures and exercises the
`UpdateExtension<T>()` / `ParseExtension<T>()` path;
- documents the source-generator namespace requirement and migration
guidance.

Targeted validation passed:

- `TypeGeneratorTests`: 17 tests on `net10.0` and `net48`;
- `ConfigurationRoundTripTests`: 4 tests on `net10.0` and `net48`.

## Related Issues

- Fixes #4014

## 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.
- [x] 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.
- [x] I have addressed **all** PR feedback received.
2026-07-18 20:15:49 +02:00

88 lines
3.1 KiB
C#

/* ========================================================================
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using Opc.Ua;
namespace MemoryBuffer
{
/// <summary>
/// Stores the configuration the test node manager
/// </summary>
// Namespaces.MemoryBuffer is generated in the same pass and is unavailable to the [DataType] generator.
[DataType(Namespace = "http://samples.org/UA/MemoryBuffer")]
public partial class MemoryBufferConfiguration
{
/// <summary>
/// The default constructor.
/// </summary>
public MemoryBufferConfiguration()
{
}
/// <summary>
/// The buffers exposed by the memory
/// </summary>
[DataTypeField(Order = 1, StructureHandling = StructureHandling.Inline)]
public ArrayOf<MemoryBufferInstance> Buffers { get; set; }
}
/// <summary>
/// Stores the configuration for a memory buffer instance.
/// </summary>
// Namespaces.MemoryBuffer is generated in the same pass and is unavailable to the [DataType] generator.
[DataType(Namespace = "http://samples.org/UA/MemoryBuffer")]
public partial class MemoryBufferInstance
{
/// <summary>
/// The default constructor.
/// </summary>
public MemoryBufferInstance()
{
}
/// <summary>
/// The browse name for the instance.
/// </summary>
[DataTypeField(Order = 1)]
public string Name { get; set; } = null!;
/// <summary>
/// The number of tags in the buffer.
/// </summary>
[DataTypeField(Order = 2)]
public int TagCount { get; set; }
/// <summary>
/// The data type of the tags in the buffer.
/// </summary>
[DataTypeField(Order = 3)]
public string DataType { get; set; } = null!;
}
}