OPC Studio User's Guide and Reference
Managed Resource License Store
Concepts > Development Concepts > Application Deployment > Licensing Elements > Managed Resource License Store
In This Topic

With the Managed Resource License Store, you embed your license key into one of the assemblies that your application comprises of.

This functionality is not available under (or the text does not apply to) COM development platform.

The main advantage of this method is that it does not require any additional actions during deployment. Also, because the Managed Resource License is the first one in the search order, you have a guarantee that if you properly place a specific valid license key into the managed resource license store, it will be the one actually used - it cannot be changed by License Manager, for example. The disadvantage of this method is that you need to put extra code and data into your application, before building it.

Concepts

Follow the steps below in order to place a license into the Managed Resource License Store and use it. The procedure is written for C# in Visual Studio, but should be similar with other managed languages and tools.

  1. Place the license key file into your project. To do so, pick a folder in your project, and in Solution Explorer, right-click on it and select Add -> Existing Item. Then, select your license key file; this is the file that has been given to you with OPC Data Client or OPC Wizard purchase. It has .BIN or .TXT extension, and its name usually starts with a "Key-Permanent-...". Press Add in order to finalize the selection.
  2. Turn the license key file in your project to an embedded resource: Select the file in Solution Explorer. Then, in the Properties window, select the Build Action row. Click on the drop-down button on its right side and select "Embedded Resource" from the list; alternatively, use up and down keys to make the same selection.
  3. Register the managed resource of the license key: At the beginning of your code, before you call any OPC Data Client or OPC Wizard operations, obtain the static Instance Field from the LicensingManagement Class, and call the RegisterManagedResource Method or RegisterManagedResourceWithExistenceCheck Method with appropriate arguments. For OPC Data Client license key, the first two arguments should always be "QuickOPC" and "Multipurpose". For OPC Wizard license key, the first two arguments should always be "OPCWizard" and "Multipurpose". The third argument determines the assembly where the license key resides; you would typically use the Assembly.GetExecutingAssembly Method here, if the resource is in the same assembly as the code that is calling the RegisterManagedResource Method or RegisterManagedResourceWithExistenceCheck Method. The fourth argument is the namespace-qualified name of the managed resource. Visual Studio determines the namespace by concatenating the default namespace (as given in project properties) with names of the project folders (starting from the project root) the embedded resource resides in. So for example, if your default namespace is MyApp, and you have placed the embedded resource with license key (named "Key-Permanent-ShareIt-1912345678-20180612.txt") to the Resources folder, the namespace-qualified name of the managed resource will be "MyApp.Resource.Key-Permanent-ShareIt-1912345678-20180612.txt". If you are unsure, use the ILDASM tool.

The available registration methods differ as follows:

The componentName and licenseId arguments of the LicensingManagement.RegisterXXXX methods are case-insensitive.

The license key registration call must be made before any OPC Data Client or OPC Wizard operation is performed, or before you attempt to retrieve the license info.

Note that the actual validity of the license key is not checked at the time when the location is registered.

Resource Name Pattern Matching

The proper determining of the managed resource namespace, and precise typing of license key file name is a common source of errors (see Troubleshooting further below). In order to alleviate such problems, you can use a resource name pattern instead of the precise resource name. The pattern uses syntax similar to the Visual Basic LIKE operator. Most importantly, you can use the asterisk ('*') widcard to represent any sequence of characters. For example, instead of passing "MyApp.Resource.Key-Permanent-ShareIt-1912345678-20180612.txt" to the RegisterManagedResource Method or the RegisterManagedResourceWithExistenceCheck Method as the resource name, pass the recommended pattern "*.Key-*.*" instead. This pattern specifies that a manage resource should be located whose full name starts with any sequence of characters (and therefore it can be in any namespace), contains "Key-" followed by any sequence of characters, and has any extension.

The specified pattern must not match more than one managed resource in the assembly, otherwise an error occurs.

The disadvantage of using the name pattern is a (slight) risk that other managed resources that happen to match the specified pattern will be found, but since you are normally in control of what managed resources go into your project, the risk can easily be mitigated.

Examples

The example below shows how to register a license located in an embedded managed resource.

// 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

 

The example below shows how to register a license located in an embedded managed resource.

// Shows how to register a license located in an embedded managed resource, verifying its existence upfront.
//
// 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.BaseLib.Portable;
using OpcLabs.EasyOpc.UA;

namespace UADocExamples.Licensing
{
    partial class _LicensingManagement
    {
        public static void RegisterManagedResourceWithExistenceCheck()
        {
            // 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.
            try
            {
                LicensingManagement.Instance.RegisterManagedResourceWithExistenceCheck("QuickOPC", "Multipurpose",
                    Assembly.GetExecutingAssembly(), "*.Key-*.*");
            }
            // This exception will be thrown if the specified managed resource does not exist or is not accessible.
            // Note, however, that the validity of the license is not checked at this point.
            // You can experiment with this code path by modifying the resource name in the call above.
            catch (CustomException customException)
            {
                Console.WriteLine($"*** Failure: {customException.Message}");
                return;
            }

            // 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, verifying its existence upfront.
'
' 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.BaseLib.Portable
Imports OpcLabs.EasyOpc.UA

Namespace Licensing
    Partial Friend Class _LicensingManagement
        Public Shared Sub RegisterManagedResourceWithExistenceCheck()

            ' 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.
            Try
                LicensingManagement.Instance.RegisterManagedResourceWithExistenceCheck("QuickOPC", "Multipurpose",
                    Assembly.GetExecutingAssembly(), "*.Key-*.*")
            Catch customException As CustomException
                Console.WriteLine($"*** Failure: {customException.Message}")
                Exit Sub
            End Try

            ' 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

 

Example: Examples - Server Licensing - Register managed resource

Example: Examples - Server Licensing - Register managed resource and verify existence

Troubleshooting 

If you use the RegisterManagedResource Method and the registration is not done properly, the component will continue the search for the license key in the order described in Licensing Elements. Usually, you will end up with a trial license instead, which is manifested by receiving a serial number other than the serial number of the license key you attempted to register. The serial number of stock demo or trial license is between 1111110000 and 1111119999 - see Examples - Client Licensing - Obtain serial number or Examples - Server Licensing - Obtain serial number.

If you use the RegisterManagedResourceWithExistenceCheck Method and the registration is not done properly, an exception is thrown.

Here are the common reasons that can cause these issues:

If you cannot rule out that the cause is in incorrect resource namespace (or resource name, in general), we recommend to use the ILDASM tool (IL Disassembler, https://docs.microsoft.com/en-us/dotnet/framework/tools/ildasm-exe-il-disassembler ) to figure out the precise actual name of your license key managed resource. You can use following steps:

 

  1. Start Developer Command Prompt for Visual Studio.
  2. Change current directory to the directory where the resulting assembly of your program resides (using the CD command).
  3. Type ILDASM PEfilename , where PEFilename is the name of your assembly file (including file extension, typically .DLL or .EXE).
  4. In the IL DASM window, double-click on the MANIFEST node.
  5. In the MANIFEST window, find the license key managed resource and verify its namespace and name with the string used in the call to the RegisterManagedResource Method. Sometimes the differences are slight and not apparent at the first site; if you do not find a difference, we recommend that you copy the relevant part of the text from the MANIFEST window into your .NET source code.

 For illustration, the part of the MANIFEST with the license key for our example looks like this:

.mresource public 'UADocExamples.Licensing.Key-DemoOrTrial-WebForm-1999003494-20180611.bin'
{
  // Offset: 0x00000000 Length: 0x00000A68
}

You will also end up with a trial license if the managed resource registration is made correctly, but the license key is not valid for some reason - for example, it does not apply to the version of the software you are runing.

See Also

Examples - Client Licensing

Examples - Server Licensing