QuickOPC User's Guide and Reference
Managed Resource License Store
Application Deployment > Licensing Elements > Managed Resource License Store
In This Topic

With the Managed Resource License Store, you embed your license 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 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 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 file; this is the file that has been given to you with QuickOPC purchase. It has .BIN extension, and its name usually starts with a "Key-Permanent-...". Press Add in order to finalize the selection.
  2. Turn the license 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. At the beginning of your code, before you call any QuickOPC operations, obtain the static Instance Field from the LicensingManagement Class, and call the RegisterManagedResource Method with appropriate arguments. The first two arguments should always be "QuickOPC" and "Multipurpose". The third argument determines the assembly where the license 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. 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.bin") to the Resources folder, the namespace-qualified name of the managed resource will be "MyApp.Resource.Key-Permanent-ShareIt-1912345678-20180612.bin". If you are unsure, use the ILDASM tool.

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

Example

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.

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

namespace UADocExamples.Licensing
{
    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.
            LicensingManagement.Instance.RegisterManagedResource("QuickOPC", "Multipurpose",
                Assembly.GetExecutingAssembly(),
                "UADocExamples.Licensing.Key-DemoOrTrial-WebForm-1999003494-20180611.bin");

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

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

Namespace UADocExamples.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.
            LicensingManagement.Instance.RegisterManagedResource("QuickOPC", "Multipurpose",
                    Assembly.GetExecutingAssembly(),
                    "UADocExamples.Licensing.Key-DemoOrTrial-WebForm-1999003494-20180611.bin")

            ' 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

 

Troubleshooting 

If 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 - Licensing - Obtain serial number.

Here are the common reasons that can cause this issue:

If you cannot rule out the 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
}
See Also

Examples - Licensing