How to use licenses.licx in a .NET Core plugin

809 Views Asked by At

I have a .NET Core class library which is being used as a plugin in an executable program. The plugin uses a licensed component from a third-party SDK, and I'm using a licenses.licx file to embed the licensing information in the output dll. I'm using Visual Studio 2019 to compile both the plugin and the executable.

When the executable program loads the plugin and tries to use it, a licensing exception is thrown from the third-party SDK. It seems as if the licensing information from the licenses.licx file in the plugin project isn't being used by the executable.

I tried referencing the plugin project directly from the executable project instead of loading the plugin dynamically, but the same issue occurs.

The only way I could get it to work was to add a licenses.licx file to the executable project with a reference to the third-part SDK. Doing this would prevent the licensing exception from being thrown and everything worked as expected. However this is not a good solution because now every licensed component that is used by a plugin has to be directly referenced by the executable project.

Is there any way I can use a licensed component in the plugin project without adding the licenses.licx file to the executable project?

1

There are 1 best solutions below

1
On BEST ANSWER

The default .NET licensing infrastructure was not designed with a plugin scenario in mind and assumes the licenses are all embedded in the executable, thus for this to be possible it really depends on how the third-party vendor implemented the integration with the .NET licensing infrastructure, so the best course of action is to contact their support team and they should be able to answer your question and hopefully provide a code example.

The three main components of .NET licensing are the LicenseManager, LicenseProvider, and LicenseContext.

The general recommendation from Microsoft is for vendors to implement their own LicenseProvider and LicenseContext and integrate with LicenseManager to perform the validation, but some vendors just use the defaults that come with .NET - and the default one scans only the executable assembly for the embedded licenses.

Depending on if/how they've implemented their custom LicenseProvider and/or LicenseContext you might be able to provide the licensing info/keys from within the plugin, before any of the controls are instantiated (the license check is usually done in the constructor of the controls).

If the vendor uses the default LicenseProvider and LicenseContext that comes with .NET, then your best bet is to try to use LicenseManager.CurrentContext.SetSavedLicenseKey(type, key); before the controls are instantiated, but you'll need to know the exact assemblies and types, and how to construct the key that it expects.