OPC Studio User's Guide and Reference
RegisterManagedResource Method
Example 



OpcLabs.BaseLib Assembly > OpcLabs.BaseLib.ComponentModel Namespace > LicensingManagement Class : RegisterManagedResource Method
Name of the licensing component for which the location of the license key should be registered. Consult the documentation for the value that corresponds to your product.

The value of this parameter cannot be null (Nothing in Visual Basic).

ID of the license key for whose location should be registered. Consult the documentation for the values to be used with your product.

The value of this parameter cannot be null (Nothing in Visual Basic).

The assembly in which the embedded managed resource resides.

The value of this parameter cannot be null (Nothing in Visual Basic).

The name of the embedded managed resource containing the license, or a pattern identifying a single such resource.

The value of this parameter cannot be null (Nothing in Visual Basic).

Registers a license key located in an embedded managed resource.
Syntax
'Declaration
 
Public Sub RegisterManagedResource( _
   ByVal componentName As String, _
   ByVal licenseId As String, _
   ByVal assembly As Assembly, _
   ByVal resourceNameOrPattern As String _
) 
'Usage
 
Dim instance As LicensingManagement
Dim componentName As String
Dim licenseId As String
Dim assembly As Assembly
Dim resourceNameOrPattern As String
 
instance.RegisterManagedResource(componentName, licenseId, assembly, resourceNameOrPattern)

Parameters

componentName
Name of the licensing component for which the location of the license key should be registered. Consult the documentation for the value that corresponds to your product.

The value of this parameter cannot be null (Nothing in Visual Basic).

licenseId
ID of the license key for whose location should be registered. Consult the documentation for the values to be used with your product.

The value of this parameter cannot be null (Nothing in Visual Basic).

assembly
The assembly in which the embedded managed resource resides.

The value of this parameter cannot be null (Nothing in Visual Basic).

resourceNameOrPattern
The name of the embedded managed resource containing the license, or a pattern identifying a single such resource.

The value of this parameter cannot be null (Nothing in Visual Basic).

Exceptions
ExceptionDescription
A license key resource is already registered for componentName and licenseId.

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

The same combination of componentName and licenseId must not (and cannot) be registered more than once. An attempt to do so will result in an System.ArgumentException. Be careful not to put the registration code into Web request handlers (without further logic) which are called repeatedly.

The actual presence and validity of the license key is not checked at the time when the location is registered. If you want an exception be thrown when the managed resource does not exist or is not accessible, use the RegisterManagedResourceWithExistenceCheck method.

Example
// Shows how to register a license located in an embedded managed resource.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using System.Reflection;
using OpcLabs.BaseLib.ComponentModel;
using OpcLabs.EasyOpc.UA;

namespace UADocExamples.Licensing
{
    partial class _LicensingManagement
    {
        public static void RegisterManagedResource()
        {
            // Register a license that is we embed as a managed resource in this program.

            // The first two arguments should always be "QuickOPC" and "Multipurpose".
            // The third argument determines the assembly where the license resides.
            // The fourth argument is the namespace-qualified name of the managed resource, or a pattern identifying it.
            // We could use precise "UADocExamples.Licensing.Key-DemoOrTrial-WebForm-1999003494-20180611.bin" instead.
            LicensingManagement.Instance.RegisterManagedResource("QuickOPC", "Multipurpose",
                Assembly.GetExecutingAssembly(), "*.Key-*.*");

            // Instantiate the client object, obtain the serial number from the license info, and display the serial number.
            var client = new EasyUAClient();
            long serialNumber = (uint)client.LicenseInfo["Multipurpose.SerialNumber"];
            Console.WriteLine("SerialNumber: {0}", serialNumber);

            // The license we ship for this purpose is a trial license with low runtime limit, so it won't be of much use.
            // But you get the point...
        }
    }
}
' Shows how to register a license located in an embedded managed resource.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports System.Reflection
Imports OpcLabs.BaseLib.ComponentModel
Imports OpcLabs.EasyOpc.UA

Namespace Licensing
    Friend Class _LicensingManagement
        Public Shared Sub RegisterManagedResource()

            ' Register a license that is we embed as a managed resource in this program.

            ' The first two arguments should always be "QuickOPC" and "Multipurpose".
            ' The third argument determines the assembly where the license resides.
            ' The fourth argument is the namespace-qualified name of the managed resource.
            ' We could use precise "UADocExamples.Licensing.Key-DemoOrTrial-WebForm-1999003494-20180611.bin" instead.
            LicensingManagement.Instance.RegisterManagedResource("QuickOPC", "Multipurpose",
                    Assembly.GetExecutingAssembly(), "*.Key-*.*")

            ' Instantiate the client object, obtain the serial number from the license info, and display the serial number.
            Dim client = New EasyUAClient()
            Dim serialNumber As Long = CUInt(client.LicenseInfo("Multipurpose.SerialNumber"))
            Console.WriteLine("SerialNumber: {0}", serialNumber)

            ' The license we ship for this purpose is a trial license with low runtime limit, so it won't be of much use.
            ' But you get the point...

        End Sub
    End Class
End Namespace
// Shows how to register a license located in an embedded managed resource.
// You can use any OPC UA client, including our Connectivity Explorer and OpcCmd utility, to connect to the server. 
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client, server and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-OPCStudio-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using System.Reflection;
using OpcLabs.BaseLib.ComponentModel;
using OpcLabs.EasyOpc.UA;

namespace UAServerDocExamples.Licensing
{
    partial class _LicensingManagement
    {
        public static void RegisterManagedResource()
        {
            // Register a license that is we embed as a managed resource in this program.

            // The first two arguments should always be "OPCWizard" and "Multipurpose".
            // The third argument determines the assembly where the license resides.
            // The fourth argument is the namespace-qualified name of the managed resource, or a pattern identifying it.
            // We could use precise "Key-DemoOrTrial-WebForm-1995003302-20240717.txt" instead.
            OpcLabs.BaseLib.ComponentModel.LicensingManagement.Instance.RegisterManagedResource("OPCWizard", "Multipurpose",
                Assembly.GetExecutingAssembly(), "*.Key-*.*");

            // Instantiate the server object, obtain the serial number from the license info, and display the serial number.
            var server = new EasyUAServer();
            long serialNumber = (uint)server.LicenseInfo["Multipurpose.SerialNumber"];
            Console.WriteLine("SerialNumber: {0}", serialNumber);

            // The license we ship for this purpose is a trial license with low runtime limit, so it won't be of much use.
            // But you get the point...
        }
    }
}
' Shows how to register a license located in an embedded managed resource.
' You can use any OPC UA client, including our Connectivity Explorer and OpcCmd utility, to connect to the server. 
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports System.Reflection
Imports OpcLabs.EasyOpc.UA

Namespace Licensing
    Partial Friend Class _LicensingManagement
        Shared Sub RegisterManagedResource()
            ' Register a license that is we embed as a managed resource in this program.

            ' The first two arguments should always be "OPCWizard" and "Multipurpose".
            ' The third argument determines the assembly where the license resides.
            ' The fourth argument is the namespace-qualified name of the managed resource, or a pattern identifying it.
            ' We could use precise "Key-DemoOrTrial-WebForm-1995003302-20240717.txt" instead.
            OpcLabs.BaseLib.ComponentModel.LicensingManagement.Instance.RegisterManagedResource("OPCWizard", "Multipurpose",
                Assembly.GetExecutingAssembly(), "*.Key-*.*")

            ' Instantiate the server object, obtain the serial number from the license info, and display the serial number.
            Dim server = New EasyUAServer()
            Dim serialNumber As Long = CUInt(server.LicenseInfo("Multipurpose.SerialNumber"))
            Console.WriteLine("SerialNumber: {0}", serialNumber)

            ' The license we ship for this purpose is a trial license with low runtime limit, so it won't be of much use.
            ' But you get the point...
        End Sub
    End Class
End Namespace
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also