Skip to content

Step 6: Writing a OPC UA ModelDesign File

Last updated on April 10, 2022

This post shows how to write the model by editing a ModelDesign file with a suitable editor

This Post is part of the OPC UA Information Model Tutorial.


It is recommended that you also read through the following page to get an overview on OPC UA Information modeling:

How to create custom OPC UA Information Models

In this tutorial we are using the example files provided in the following repository:

Especially the file FooFltModel.xml

A more complete example with heavy use of heavy usage of ModelDesign files and dependencies between them is shown in this project (look into subfolders with the name opcua):


If you are using Visual Studio, make sure that you set up Visual Studio as mentioned here:

Step 3: Setup Visual Studio as ModelDesign Editor


Namespaces help to avoid naming conflicts by prefixing them to variable names. Apart from that, they also split the whole address space in the server into multiple groups.

The following code shows the minimum code required for an empty ModelDesign with comments indicating the designated model components. A lot of the boiler-plate code is concerned with namespaces, which are discussed in this section.

<?xml version="1.0" encoding="utf-8"?>


    <!--No space allowed at the beginning of the namespace URL!
      Prefix sets the filenames of the generated files. -->
    <Namespace Name="FooZbrFlt" Prefix="FooFlt"></Namespace>
    <Namespace Name="OpcUa" Version="1.03" PublicationDate="2013-12-02T00:00:00Z"></Namespace>
  <!-- ObjectType -->
  <!-- ReferenceType -->
  <!-- VariableType -->
  <!-- DataType -->
  <!-- Object -->
  <!-- Variable -->
  <!-- Property -->
  <!-- Dictionary -->
  <!-- Method -->
  <!-- View -->
  <!-- Instantiate at least one variable (or object, or view, or ...) in namespace.
    Compiling an empty namespace will fail with error message:
	  Object reference not set to an instance of an object.
	See -->
  <View SymbolicName="FooZbrFlt:MyView">
    <Description>Dummy view</Description>
      <Reference IsInverse="true">

The XML element ModelDesign has the following attributes:

  • xmlns:uax=""
    • The link leads to a schema file that defines various complexTypes used by OPCFoundation.
  • xmlns:xsi=""
    • required
  • xmlns:ua=""
    • Namespace of all OPCFoundation
  • xmlns:FooZbrFlt=""
    • this document may use elements of namespace FooZbrFlt. In combination with TargetNamespace this document may define ObjectType elements in that namespace as well as use them from that namespace, as long as their names are correctly prefixed with FooZbrFlt:.
  • xmlns:xsd=""
  • TargetNamespace=""
    • this document defines elements in this namespace
  • TargetVersion="0.9.0"
    • optional, used as auxiliary release meta-information
  • TargetPublicationDate="2020-05-01T00:00:00Z"
    • optional, used as auxiliary release meta-information
  • xmlns=""
    • Default namespace of this document


Define method types explicitly (grey box) and use them via TypeDefinition for method nodes as shown for method MyMethod. Defining methods in-places like MyMethodInPlace will not expose Input- and OutputArguments to the OPC UA client.

Note: In comparison to Object/ObjectType and Variable/VariableType, Method do not have MethodType.

Published inInformation Modeling


  1. Max Dubinski Max Dubinski

    Hi, i am using the approach described in the tutorial to create some objects with some methods. I defined method definitions and methods in objects referring to these method definitions via TypDefinition attribute. Then generated .c and .h Files using UA-ModelCompiler and nodeset_compiler.
    The problem comes from generated code. It calls UA_Server_addNode for method definitions for nodeID=0 and this call fails, with UA_STATUSCODE_BADPARENTNODEIDINVALID
    Will appreciate any help

  2. Karl Mayr Karl Mayr

    To check if my recently compiled ModelCompiler (on VS2017) works, I tried to compile the above example (minimum code required for an empty ModelDesign). I expected to get an “empty” NodeSet2 file (without objects).
    But unexpected errors occur:
    Object reference not set to an instance of an object.
    at ModelCompiler.ModelCompilerValidator.Validate2(IList`1 designFilePaths, String identifierFilePath, Boolean generateIds) in C:\GIT\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 1213 at ModelCompiler.ModelGenerator2.ValidateAndUpdateIds(IList`1 designFilePaths, String identifierFilePath, UInt32 startId, String specificationVersion) in C:\GIT\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 98 at ModelCompiler.Program.ProcessCommandLine2(List`1 tokens) in C:\GIT\UA-ModelCompiler\ModelCompiler\Program.cs:line 422
    Was the ModelCompiler not compiled correctly or is it not possible by design to create this empty NodeSet2 file as a first test ?

    • Benedict Simlinger Benedict Simlinger


      what is the git commit ID of the ModelCompiler you’re using?

      Your ModelCompiler is probably compiled correctly, but there is still a chance for bugs. The edge case “empty NodeSet2” is likely to trigger such a bug.

      I can’t answer your question with confidence, but I don’t see why you should not be able to create an “empty” NodeSet2 file (I assume that also excludes type definitions etc.).

      Can you compile a NodeSet2 with just a single object?
      To test this, take and remove all Type Definitions, so that you’re left with the boiler plate code on top and the object FooZbrFlt:Ape. Change it’s TypeDefinition to something basic.

      Let me know of any progress or insights on your side.
      It may take me some days to get access to my dev environment and test your question myself.

      Kind regards!

  3. Bob Janssen Bob Janssen

    Hi, the processing of namespaces and elements of the design in general can be a bit tricky. It appears that the model compiler imports nodes sequentially. In case a node refers to another node, be it a specialisation, association or composition, the compiler throws an errror when the target of the reference hasn’t been imported yet. I’ve been trying to import multiple namespaces and was forced to put things in sequence. For one, I created a different design file for each namespace that fed one after the other into the model compiler. And circular references imply a ticket to dependency hell.

    It strikes me as odd that the import should be so sensitive to dependencies.
    Any tips for clever model design in this respect.

    • Benedict Simlinger Benedict Simlinger

      Hi Bob,

      sorry for my late reply. I can not offer you a solution but I can tell you, that I have experienced the model builder to be sensitive to the order of models/namespaces too.

      I did not come up with any best-practice advice to share here with you, but I also have to admit that my models never warranted to thorough search for a general solution since the issue was usually identified and fixed quickly.

      Can you give me an example for a circular reference that has some real-world application?

Leave a Reply

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.