# OpcClient.AddReference Method

> Reference: Adds a new reference to existing nodes in the address space hierarchy using the command specified.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcClient</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx.client">Opc.UaFx.Client</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
<dt>Members</dt>
<dd><a href="./members">OpcClient Members</a></dd>
<dt>Also in</dt>
<dd>Opc.UaFx.Client</dd>
</dl>

<span class="api-meta">5 overloads · since v2.7</span>

| Overload | Description |
|---|---|
| [AddReference(OpcAddReference)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/addreference#addreference-opc-uafx-opcaddreference)<span class="api-meta">since v2.7</span> | Adds a new reference to existing nodes in the address space hierarchy using the `command` specified. |
| [AddReference(OpcNodeId, OpcNodeId, OpcNodeCategory)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/addreference#addreference-opc-uafx-opcnodeid-opc-uafx-opcnodeid-opc-uafx-opcnodecategory)<span class="api-meta">since v2.7</span> | Adds a new reference to existing nodes in the address space hierarchy using the identifiers of the nodes which shall reference each other. |
| [AddReference(OpcNodeId, OpcNodeId, OpcNodeCategory, OpcReferenceDirection)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/addreference#addreference-opc-uafx-opcnodeid-opc-uafx-opcnodeid-opc-uafx-opcnodecategory-opc-uafx-opcreferencedirection)<span class="api-meta">since v2.7</span> | Adds a new reference to existing nodes in the address space hierarchy using the identifiers of the nodes which shall reference each other using the `direction` specified. |
| [AddReference(OpcNodeId, OpcNodeId, OpcNodeCategory, OpcReferenceDirection, OpcReferenceType)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/addreference#addreference-opc-uafx-opcnodeid-opc-uafx-opcnodeid-opc-uafx-opcnodecategory-opc-uafx-opcreferencedirection-opc-uafx-opcreferencetype)<span class="api-meta">since v2.7</span> | Adds a new reference to existing nodes in the address space hierarchy using the identifiers of the nodes which shall reference each other using the `direction` specified. |
| [AddReference(OpcNodeId, OpcNodeId, OpcNodeCategory, OpcReferenceDirection, OpcNodeId)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.client.opcclient/addreference#addreference-opc-uafx-opcnodeid-opc-uafx-opcnodeid-opc-uafx-opcnodecategory-opc-uafx-opcreferencedirection-opc-uafx-opcnodeid)<span class="api-meta">since v2.7</span> | Adds a new reference to existing nodes in the address space hierarchy using the identifiers of the nodes which shall reference each other using the `direction` specified. |

**Exceptions (all overloads)**

| Exception | Condition |
|---|---|
| [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception) | The object has been disposed of. |
| [OpcException](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcexception/) | The service execution failed upon different circumstances; for more details see exception details. The following issues can lead to that exception: [BadNothingToDo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnothingtodo) and [BadTooManyOperations](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtoomanyoperations). |

## AddReference(OpcAddReference)

<span class="api-meta">since v2.7</span>

Adds a new reference to existing nodes in the address space hierarchy using the `command` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStatus AddReference(OpcAddReference command)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AddReference(command As OpcAddReference) As OpcStatus
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `command` | [OpcAddReference](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcaddreference/) | The [OpcAddReference](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcaddreference/) instance to process. |

**Returns**

[OpcStatus](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatus/)

An instance of the [OpcStatus](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatus/) class which contains the information about the outcome of the processed command.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `command` is a null reference (Nothing in Visual Basic). |
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The add node service is currently not supported, especially using the `command` specified. |

**Remarks**

Known results for the `command` specified are:

| Status | Description |
|---|---|
| [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid) | For more details see [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid). |
| [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid) | For more details see [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid). |
| [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid) | For more details see [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid). |
| [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid) | For more details see [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid). |
| [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid) | For more details see [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid). |
| [BadReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencenotallowed) | The reference could not be created because it violates constraints imposed by the data model on this server. |
| [BadReferenceLocalOnly](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencelocalonly) | The reference type is not valid for a reference to a remote server. |
| [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied) | For more details see [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied). |
| [BadDuplicateReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badduplicatereferencenotallowed) | The reference type between the nodes is already defined. |
| [BadInvalidSelfReference](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badinvalidselfreference) | The server does not allow this type of self reference on this node. |

## AddReference(OpcNodeId, OpcNodeId, OpcNodeCategory)

<span class="api-meta">since v2.7</span>

Adds a new reference to existing nodes in the address space hierarchy using the identifiers of the nodes which shall reference each other. The new reference will be a [ParentToChild](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencedirection/#parenttochild) relation using [Organizes](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencetype/#organizes) as the type of reference.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStatus AddReference(
    OpcNodeId nodeId,
    OpcNodeId targetNodeId,
    OpcNodeCategory targetNodeCategory)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AddReference(
    nodeId As OpcNodeId,
    targetNodeId As OpcNodeId,
    targetNodeCategory As OpcNodeCategory) As OpcStatus
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `nodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) through that the source node can be identified and accessed. This identifier refers to the 'child' node. |
| `targetNodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) through that the target node can be identified and accessed. This identifier referes to the 'parent' node. |
| `targetNodeCategory` | [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) | One of the members defined by the [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) enumeration which is used by the server to validate that the reference to be added matches the [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) of the target node identified by the `targetNodeId`. |

**Returns**

[OpcStatus](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatus/)

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `nodeId` or `targetNodeId` is equals [Null](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/members#null). |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `nodeId` or `targetNodeId` is a null reference (Nothing in Visual Basic). |
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The add node service is currently not supported, especially using the parameters specified. |

**Remarks**

Known results for the service invocation are:

| Status | Description |
|---|---|
| [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid) | For more details see [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid). |
| [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid) | For more details see [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid). |
| [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid) | For more details see [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid). |
| [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid) | For more details see [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid). |
| [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid) | For more details see [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid). |
| [BadReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencenotallowed) | The reference could not be created because it violates constraints imposed by the data model on this server. |
| [BadReferenceLocalOnly](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencelocalonly) | The reference type is not valid for a reference to a remote server. |
| [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied) | For more details see [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied). |
| [BadDuplicateReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badduplicatereferencenotallowed) | The reference type between the nodes is already defined. |
| [BadInvalidSelfReference](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badinvalidselfreference) | The server does not allow this type of self reference on this node. |

## AddReference(OpcNodeId, OpcNodeId, OpcNodeCategory, OpcReferenceDirection)

<span class="api-meta">since v2.7</span>

Adds a new reference to existing nodes in the address space hierarchy using the identifiers of the nodes which shall reference each other using the `direction` specified. The new reference will use the relation defined by `direction` using the [Organizes](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencetype/#organizes) as the type of reference.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStatus AddReference(
    OpcNodeId nodeId,
    OpcNodeId targetNodeId,
    OpcNodeCategory targetNodeCategory,
    OpcReferenceDirection direction)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AddReference(
    nodeId As OpcNodeId,
    targetNodeId As OpcNodeId,
    targetNodeCategory As OpcNodeCategory,
    direction As OpcReferenceDirection) As OpcStatus
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `nodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) through that the source node can be identified and accessed. |
| `targetNodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) through that the target node can be identified and accessed. |
| `targetNodeCategory` | [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) | One of the members defined by the [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) enumeration which is used by the server to validate that the reference to be added matches the [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) of the target node identified by the `targetNodeId`. |
| `direction` | [OpcReferenceDirection](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencedirection/) | One of the members defined by the [OpcReferenceDirection](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencedirection/) enumeration which defines the kind of relation the reference will construct. |

**Returns**

[OpcStatus](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatus/)

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `nodeId` or `targetNodeId` is equals [Null](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/members#null). |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `nodeId` or `targetNodeId` is a null reference (Nothing in Visual Basic). |
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The add node service is currently not supported, especially using the parameters specified. |

**Remarks**

Known results for the service invocation are:

| Status | Description |
|---|---|
| [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid) | For more details see [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid). |
| [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid) | For more details see [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid). |
| [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid) | For more details see [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid). |
| [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid) | For more details see [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid). |
| [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid) | For more details see [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid). |
| [BadReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencenotallowed) | The reference could not be created because it violates constraints imposed by the data model on this server. |
| [BadReferenceLocalOnly](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencelocalonly) | The reference type is not valid for a reference to a remote server. |
| [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied) | For more details see [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied). |
| [BadDuplicateReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badduplicatereferencenotallowed) | The reference type between the nodes is already defined. |
| [BadInvalidSelfReference](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badinvalidselfreference) | The server does not allow this type of self reference on this node. |

## AddReference(OpcNodeId, OpcNodeId, OpcNodeCategory, OpcReferenceDirection, OpcReferenceType)

<span class="api-meta">since v2.7</span>

Adds a new reference to existing nodes in the address space hierarchy using the identifiers of the nodes which shall reference each other using the `direction` specified. The new reference will use the relation defined by `direction` using the `referenceType` specified as the type of reference.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStatus AddReference(
    OpcNodeId nodeId,
    OpcNodeId targetNodeId,
    OpcNodeCategory targetNodeCategory,
    OpcReferenceDirection direction,
    OpcReferenceType referenceType)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AddReference(
    nodeId As OpcNodeId,
    targetNodeId As OpcNodeId,
    targetNodeCategory As OpcNodeCategory,
    direction As OpcReferenceDirection,
    referenceType As OpcReferenceType) As OpcStatus
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `nodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) through that the source node can be identified and accessed. |
| `targetNodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) through that the target node can be identified and accessed. |
| `targetNodeCategory` | [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) | One of the members defined by the [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) enumeration which is used by the server to validate that the reference to be added matches the [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) of the target node identified by the `targetNodeId`. |
| `direction` | [OpcReferenceDirection](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencedirection/) | One of the members defined by the [OpcReferenceDirection](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencedirection/) enumeration which defines the kind of relation the reference will construct. |
| `referenceType` | [OpcReferenceType](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencetype/) | One of the members defined by the [OpcReferenceType](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencetype/) enumeration to use to setup the reference between the source and the target node identified by the `nodeId` and the `targetNodeId`. |

**Returns**

[OpcStatus](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatus/)

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `nodeId` or `targetNodeId` is equals [Null](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/members#null). |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `nodeId` or `targetNodeId` is a null reference (Nothing in Visual Basic). |
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The add node service is currently not supported, especially using the parameters specified. |

**Remarks**

Known results for the service invocation are:

| Status | Description |
|---|---|
| [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid) | For more details see [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid). |
| [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid) | For more details see [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid). |
| [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid) | For more details see [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid). |
| [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid) | For more details see [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid). |
| [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid) | For more details see [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid). |
| [BadReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencenotallowed) | The reference could not be created because it violates constraints imposed by the data model on this server. |
| [BadReferenceLocalOnly](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencelocalonly) | The reference type is not valid for a reference to a remote server. |
| [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied) | For more details see [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied). |
| [BadDuplicateReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badduplicatereferencenotallowed) | The reference type between the nodes is already defined. |
| [BadInvalidSelfReference](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badinvalidselfreference) | The server does not allow this type of self reference on this node. |

## AddReference(OpcNodeId, OpcNodeId, OpcNodeCategory, OpcReferenceDirection, OpcNodeId)

<span class="api-meta">since v2.7</span>

Adds a new reference to existing nodes in the address space hierarchy using the identifiers of the nodes which shall reference each other using the `direction` specified. The new reference will use the relation defined by `direction` using the type of reference identified by the `referenceTypeId` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStatus AddReference(
    OpcNodeId nodeId,
    OpcNodeId targetNodeId,
    OpcNodeCategory targetNodeCategory,
    OpcReferenceDirection direction,
    OpcNodeId referenceTypeId)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AddReference(
    nodeId As OpcNodeId,
    targetNodeId As OpcNodeId,
    targetNodeCategory As OpcNodeCategory,
    direction As OpcReferenceDirection,
    referenceTypeId As OpcNodeId) As OpcStatus
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `nodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) through that the source node can be identified and accessed. |
| `targetNodeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) through that the target node can be identified and accessed. |
| `targetNodeCategory` | [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) | One of the members defined by the [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) enumeration which is used by the server to validate that the reference to be added matches the [OpcNodeCategory](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodecategory/) of the target node identified by the `targetNodeId`. |
| `direction` | [OpcReferenceDirection](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencedirection/) | One of the members defined by the [OpcReferenceDirection](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcreferencedirection/) enumeration which defines the kind of relation the reference will construct. |
| `referenceTypeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) which identifies the type of reference to use to setup the reference between the source and the target node identified by the `nodeId` and the `targetNodeId`. |

**Returns**

[OpcStatus](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatus/)

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `nodeId`, `targetNodeId` or `referenceTypeId` is equals [Null](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/members#null). |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `nodeId`, `targetNodeId` or `referenceTypeId` is a null reference (Nothing in Visual Basic). |
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The add node service is currently not supported, especially using the parameters specified. |

**Remarks**

Known results for the service invocation are:

| Status | Description |
|---|---|
| [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid) | For more details see [BadSourceNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badsourcenodeidinvalid). |
| [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid) | For more details see [BadReferenceTypeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencetypeidinvalid). |
| [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid) | For more details see [BadServerUriInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badserveruriinvalid). |
| [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid) | For more details see [BadTargetNodeIdInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badtargetnodeidinvalid). |
| [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid) | For more details see [BadNodeClassInvalid](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badnodeclassinvalid). |
| [BadReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencenotallowed) | The reference could not be created because it violates constraints imposed by the data model on this server. |
| [BadReferenceLocalOnly](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badreferencelocalonly) | The reference type is not valid for a reference to a remote server. |
| [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied) | For more details see [BadUserAccessDenied](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#baduseraccessdenied). |
| [BadDuplicateReferenceNotAllowed](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badduplicatereferencenotallowed) | The reference type between the nodes is already defined. |
| [BadInvalidSelfReference](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstatuscode/#badinvalidselfreference) | The server does not allow this type of self reference on this node. |
