.NET 5.0 在 .licx 文件中引用库会导致构建时错误

问题描述

简介

我们正在尝试将库移植到 .NET 5.0,但遗憾的是在此过程中遇到了意外错误。 我们的一个库已签名并包含一个使用 .NET LicenseProvider 类进行许可证检查的类。许可配置需要设计时调用,并且可以像这样实现(仅作为示例)。

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");
                }
            }
        }
    }

许可检查如下:

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

所以我们使用所需的类引用库,将它的引用添加.licx 文件,但在构建之后会生成如下错误

    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)'

.licx删除引用会消除构建错误,但正如预期的那样,会在许可证检查期间导致运行时错误,因为设计时构建不会运行。

附件

具有所描述错误的示例项目:Sample Project Link

问题

是否知道如何解决构建错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)