.NET 5.0 Referencing library in .licx file cause build time errors

0

Introduction

We're trying to port a library to .NET 5.0, but sadly faced an unexpected error during this process. One of our libraries is signed and contains a class that uses .NET LicenseProvider class for license check. Design time invocation is required for licensing configuration and might be implemented (just for example) like this.

public class ChartLicenseProvider : LicenseProvider
    {
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            if (context.UsageMode == LicenseUsageMode.Designtime)
            {
                MessageBox.Show("Build time.", "title");
                context.SetSavedLicenseKey(type, "1");
                return new ChartLicense("test");
            }
            else
            {
                var ttt = context.GetSavedLicenseKey(type, null);
                if (ttt == "1") return new ChartLicense("test");
                else
                {
                    throw new LicenseException(type, instance, "gg lic exception");
                }
            }
        }
    }

License check is made as following:

public CustomControl1()
{
    LicenseManager.Validate(typeof(CustomControl1));
}

So we reference the library with the required class, adding it's reference to .licx file, but after that build generates errors like that:

    LC : error LC0000: 'Could not load file or assembly 'PresentationFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)'

Deleting the reference from .licx removes the build errors, but as expected causes runtime errors during license check, because design time build doesn't run.

Attachments

Sample project with the described errors: Sample Project Link.

Question

Is there any idea how can the build errors be solved?

c#
.net
dll
licensing
.net-5

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0