# OpcServerApplication&lt;T&gt; Members

> Reference: Provides a base class for applications which host a server of the type T and start it when the application is run.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcServerApplication&lt;T&gt;</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx.server">Opc.UaFx.Server</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
</dl>

Inherits members from [OpcApplication](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members).

## Constructors

### OpcServerApplication

<span class="api-meta">2 overloads</span>

| Overload | Description |
|---|---|
| [OpcServerApplication()](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#opcserverapplication-noparams) | Initializes a new instance of the [OpcServerApplication&lt;T&gt;](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/) class which hosts a new instance of the type `T`. |
| [OpcServerApplication(T)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#opcserverapplication-t0) | Initializes a new instance of the [OpcServerApplication&lt;T&gt;](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/) class using the `server` specified. |

**Exceptions (all overloads)**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | An application has already been created on the current thread and has not yet been exited (see [Current](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#current)). |

#### OpcServerApplication()

Initializes a new instance of the [OpcServerApplication&lt;T&gt;](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/) class which hosts a new instance of the type `T`.

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

```csharp
public OpcServerApplication()
```

</div>

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

```vbnet
Public Sub New()
```

</div>

#### OpcServerApplication(T)

Initializes a new instance of the [OpcServerApplication&lt;T&gt;](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/) class using the `server` specified.

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

```csharp
public OpcServerApplication(T server)
```

</div>

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

```vbnet
Public Sub New(server As T)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `server` | T | The server to host. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `server` is a null reference (Nothing in Visual Basic). |

## Properties

### Configuration

<span class="api-meta">override</span>

Gets the configuration of the [Server](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#server).

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

```csharp
public override OpcApplicationConfiguration Configuration { get; }
```

</div>

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

```vbnet
Public Overrides ReadOnly Property Configuration As OpcApplicationConfiguration
```

</div>

**Property value**

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

The [Configuration](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverbase/members#configuration) of the [Server](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#server).

**Overrides**

[Configuration](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#configuration)

### Server

Gets the server hosted by the application.

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

```csharp
public T Server { get; }
```

</div>

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

```vbnet
Public ReadOnly Property Server As T
```

</div>

**Property value**

T

The instance of the type `T` hosted by the application.

## Methods

### ExitCore

<span class="api-meta">protected · override</span>

Stops the [Server](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#server) and raises the [Exiting](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#exiting) and [Exited](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#exited) events.

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

```csharp
protected override void ExitCore()
```

</div>

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

```vbnet
Protected Overrides Sub ExitCore()
```

</div>

**Overrides**

[ExitCore](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#exitcore)

**Remarks**

The method does nothing unless the [State](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverbase/members#state) of the [Server](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#server) is [Started](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverstate/#started).

### LoadConfigurationCore

<span class="api-meta">protected · override</span>

Loads the server configuration from the configuration section with the `configSectionName` specified and assigns it to the [Server](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#server).

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

```csharp
protected override void LoadConfigurationCore(string configSectionName)
```

</div>

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

```vbnet
Protected Overrides Sub LoadConfigurationCore(configSectionName As String)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `configSectionName` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the configuration section or a null reference (Nothing in Visual Basic) to use the full name of the type `T`. |

**Overrides**

[LoadConfigurationCore](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#loadconfigurationcore)

### RunCore

<span class="api-meta">protected · override</span>

Starts the [Server](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#server) and waits until the application exits.

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

```csharp
protected override int RunCore()
```

</div>

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

```vbnet
Protected Overrides Function RunCore() As Integer
```

</div>

**Returns**

[Int32](https://learn.microsoft.com/dotnet/api/system.int32)

The [ExitCode](https://learn.microsoft.com/dotnet/api/system.environment.exitcode).

**Exceptions**

| Exception | Condition |
|---|---|
| [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) | The [Server](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverapplication-1/members#server) is being started or has been started. |

**Overrides**

[RunCore](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcapplication/members#runcore)

**Remarks**

The method starts the server only in the state [Created](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverstate/#created) or [Stopped](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserverstate/#stopped); in any other state it returns at once. In an interactive environment (see [UserInteractive](https://learn.microsoft.com/dotnet/api/system.environment.userinteractive)) the method reports the result on the console, waits for a key and exits the application. Otherwise the method returns at once if starting failed, without passing on the exception, and else waits until the application is exited.
