Skip to content

Keep modelling rules of children in generated InitializationStrings - #260

Closed
romanett wants to merge 3 commits into
OPCFoundation:masterfrom
romanett:romanett/modelcompiler-issue-3972-b66649
Closed

romanett wants to merge 3 commits into
OPCFoundation:masterfrom
romanett:romanett/modelcompiler-issue-3972-b66649

Conversation

@romanett

@romanett romanett commented Sep 30, 2026 •

Copy link
Copy Markdown

Description

Fixes the ModelCompiler part of OPCFoundation/UA-.NETStandard#3972: AddIns such as BuildingBlock1/BuildingBlock2 from the repro in OPCFoundation/UA-.NETStandard#3843 were missing at runtime with 1.5.378.152.

Root cause

ClearModellingRules removed the ModellingRuleId from the instance state of a type and from all of its children. That instance state becomes the InitializationString of the generated class. Some children don't get a generated property, such as AddIns below Identification. The stack stores those as extra, dynamic children. Because their modelling rule had been stripped, the pruning in 1.5.378.152 (OPCFoundation/UA-.NETStandard#3843) removed them, since it only keeps dynamic children with a Mandatory/Optional rule.

Fix

  • For the instance state of a type, only the instance's own modelling rule is cleared. The rules of the instance declarations below it are kept. Default permissions and access restrictions are still applied to all children.
  • Standalone instances are unchanged.
  • Removed leftover debug Console.WriteLine("x") blocks in ModelDesignerValidator.ClearModellingRules and ModelGenerator2.ConstructInitializer.

With the repro NodeSet, the generated DemoMachineTypeState initializer now carries ModellingRuleId = i=78 for Identification, BuildingBlock1 and BuildingBlock2. The instance itself still has no modelling rule.

Behavior change

Children of instances created from generated classes now expose a HasModellingRule reference when browsed. The 2.0 (master) source generator already emits ModellingRuleId on every generated child, so this matches it.

Tests

  • New InstanceModellingRuleTests generates code from a small NodeSet (type → Mandatory FolderType child → Mandatory child unknown to FolderState). It decodes the InitializationString and checks the modelling rules. It fails without the fix (Expected: i=78, Actual: null) and passes with it.

Notes

  • Bumps OPCFoundation.NetStandard.Opc.Ua.Core/Types from 1.5.378.152 (no longer on nuget.org, restore failed with NU1603) to 1.5.378.176, the version of the Stack submodule.
  • The build workflow fails at checkout for PRs from forks (Input required and not supplied: token), because the fork doesn't get the repository secrets.
  • The VirtualFileSystem* tests fail locally with an ObjectDisposedException (memory-mapped file). That code is unrelated to this change.

🤖 Generated with Claude Code

romanett and others added 3 commits September 30, 2026 08:16
ClearModellingRules removed the modelling rule from the instance state of a
type and from all of its children. The instance state is emitted as the
InitializationString of the generated class, so children without a strongly
typed property (e.g. AddIns below Identification) were decoded without a
ModellingRuleId and pruned at runtime by the stack (1.5.378.152).

Only clear the modelling rule of the instance itself and keep the rules of
the instance declarations below it. Standalone instances are unchanged.

Also removes leftover debug output.

Fixes OPCFoundation/UA-.NETStandard#3972

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1.5.378.152 is no longer available on nuget.org, which breaks restore (NU1603).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Secrets are not available to workflows triggered from forks, so checkout
failed with 'Input required and not supplied: token'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants