How do I use SubtypeOverride?

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
VC-JK
Full Member
Full Member
Posts: 5
Joined: 21 Mar 2025, 11:06

How do I use SubtypeOverride?

Post by VC-JK »

Hello everybody,

in https://forum.unified-automation.com/viewtopic.php?f=38&t=8239 I read the support team mentioning the SubtypeOverride. Since I am trying to implement a method which creates the instance of a parent object which includes various child objects. These child objects have be Subtypes.

Lets assume for example that my information model looks like this:

Code: Select all

MyInformationModel
└─ ObjectTypes
   ├─ MyParentObjectType
   │  ├─ MyChildObject1 (Component, Type: MyChildObject1Type)
   │  └─ MyChildObject2 (Component, Type: MyChildObject2Type)
   │
   ├─ MyChildObject1Type
   │  ├─ MandatoryVariable1      : <DataType>  [Mandatory]
   │  └─ OptionalVariable1       : <DataType>  [Optional]
   │
   │  └─ MyChildObject1Subtype  (SubtypeOf: MyChildObject1Type)
   │     ├─ MandatoryVariable1   : <DataType>  [Mandatory]
   │     └─ OptionalVariable1    : <DataType>  [Mandatory]   // upgraded to mandatory
   │
   └─ MyChildObject2Type
      ├─ VariableA               : <DataType>  [Mandatory]
      └─ VariableB               : <DataType>  [Mandatory]
What I am trying now is to use SubtypeOverride to create an instance of MyParentObject which has components of the types MyChildObject1SubType und MyChildObject2Type. When using the following code, only MyParentObject_123 is created with standard MyChildObject1 and MyChildObject2:

Code: Select all

reateObjectSettings myParentObjectSettings = new CreateObjectSettings()
{
    BrowseName = new QualifiedName("MyParentObject_123", DefaultNamespaceIndex),
    EventNotifier = EventNotifiers.SubscribeToEvents,
    NotifierParent = new NodeId(Objects.MyFolder, DefaultNamespaceIndex),
    ParentNodeId = new NodeId(Objects.MyFolder, DefaultNamespaceIndex),
    ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
    RequestedNodeId = new NodeId("MyParentObject_123", DefaultNamespaceIndex),
    TypeDefinitionId = new NodeId(ObjectTypes.MyParentObjectType, DefaultNamespaceIndex),
    SubtypeOverrides = new List<SubtypeOverride>
	{
    		new SubtypeOverride
    		(
        		AbsoluteName.ToString(new QualifiedName("MyChildObject1Type", DefaultNamespaceIndex)),
        		new NodeId(ObjectTypes.MyChildObject1Subtype)
    		)
	}
};
ObjectNode myParentObjectNode = CreateObject(Server.DefaultRequestContext, myParentObjectSettings );


MyParentObjectModel myParentObject = new MyParentObjectModel();
LinkModelToNode(myParentObjectNode.NodeId, myParentObject , null, null, 500);
Do you have any idea what I am doing wrong? Or is there another way to enforce the creation of another ObjectType when I am instanciating a parent object with various children?

Thank you and best regards,
JK

User avatar
Support Team
Hero Member
Hero Member
Posts: 3329
Joined: 18 Mar 2011, 15:09

Re: How do I use SubtypeOverride?

Post by Support Team »

Hi,

thank you for reporting the issue. Currently there is an issue in the SDK that if an instance was created with SubtypeOverrides or ChildrenSettings to specify an alternative TypeDefinition for a child, and that TypeDefinition itself contains child overrides, those overrides are not applied to the instance.

This will get fixed in SDK version 4.2.3.

As a workaround you can specify the child that is mandatory now in the ChildrenSettings.

Code: Select all

                var settings = new CreateObjectSettings()
                {
                    BrowseName = new QualifiedName("MyParentObject_123", DefaultNamespaceIndex),
                    EventNotifier = EventNotifiers.SubscribeToEvents,
                    NotifierParent = new NodeId(Objects.MyFolder, DefaultNamespaceIndex),
                    ParentNodeId = new NodeId(Objects.MyFolder, DefaultNamespaceIndex),
                    ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
                    RequestedNodeId = new NodeId("MyParentObject_123", DefaultNamespaceIndex),
                    TypeDefinitionId = new NodeId(ObjectTypes.MyParentObjectType, DefaultNamespaceIndex),
                    ChildrenSettings = new List<ChildInstanceSettings>()
                    {
                        new ChildObjectSettings()
                        {
                             BrowsePath = { AbsoluteNames.MyChildObject1 , },
                             TypeDefinitionId = ObjectTypeIds.MyChildObject1Subtype.ToNodeId(Server.NamespaceUris),
                        },
                        new ChildVariableSettings()
                        {
                            BrowsePath = { AbsoluteNames.MyChildObject1, AbsoluteNames.OptionalVariable1, },
                        },
                    },
                };
                CreateObject(Server.DefaultRequestContext, settings);
Best regards
Unified Automation Support Team

Post Reply