【问题标题】:Rhino-Licensing for .NET is throwing an LicenseExpiredException.NET 的 Rhino-Licensing 抛出 LicenseExpiredException
【发布时间】:2016-06-16 22:17:45
【问题描述】:

我正在使用带有最新 .NET 核心的 Windows 8.1Visual Studio 2015。我按照 James Gregory 的 following article 创建了一个 Winform 应用程序。但是当我声明许可证时,它给了我以下错误:Rhino.Licensing.LicenseExpiredException was unhandled HResult=-2146233088 Message=Expiration Date : 6/16/2016 12:00:00 AM Source=Rhino.Licensing StackTrace: at Rhino.Licensing.AbstractLicenseValidator.HasExistingLicense() at Rhino.Licensing.AbstractLicenseValidator.AssertValidLicense() at Rhino.Licensing.LicenseValidator.AssertValidLicense() at Winfrm_RhinoTest.Form1.ApplyLicense()....

代码于 2016 年 6 月 15 日运行,到期日期设置为 2016 年 6 月 16 日。

生成许可证的C#代码如下:

string publicKey = File.ReadAllText("publicKey.xml");
            new LicenseValidator(publicKey, @"C:\Users\Public\license.xml").AssertValidLicense();

生成license.xml文件,在代码中使用如下:

<?xml version="1.0" encoding="utf-8"?>
<license id="b45c43a5-a639-4fa4-8bf7-38531b19072e" expiration="2016-06-16T00:00:00.0000000" type="Trial">
  <name>Bilbo</name>
  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    <SignedInfo>
      <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
      <Reference URI="">
        <Transforms>
          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
        </Transforms>
        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
        <DigestValue>d+eI2/Bdp/VYJ8pi/ufmJGeRW6k=</DigestValue>
      </Reference>
    </SignedInfo>
    <SignatureValue>Zd2oTinP0zE4/4haA5e4810MdG3upx1LlzkXALsTJYDgXLacDoc96diObTkxDipUBMUeFuf3ARBPtFRHGIqHjEfhn/FqZD+CrcsvjhbMSIROpaqqcOpzFwOamjQ+jPLW+BOf5qvMA0n4LNCm8B5qnifc/08zTXTSUpAqLiCY8zk=</SignatureValue>
  </Signature>
</license>

【问题讨论】:

    标签: c# .net winforms visual-studio-2015 rhino-licensing


    【解决方案1】:

    source code for rhino-licensing中,日期比较是在UTC中完成的

    result = DateTime.UtcNow < ExpirationDate;
    

    这会抛出以Expiration Date为参数的异常

    throw new LicenseExpiredException("Expiration Date : " + ExpirationDate)
    

    由于您显示的异常表明 ExpirationDate 是 6 月 16 日开始,因此最可能的原因是您在您的时区中运行代码,即 6 月 15 日,实际上已经是 6 月 16 日(UTC 时间已经 19 小时)在这篇文章的时候。

    【讨论】:

    • 感谢well explained 导致错误并帮助这篇文章的读者(包括我自己)。我在 2016 年 6 月 15 日美国东部时间晚上 11:30 左右进行了测试,比 UTC 时区晚 4 小时。我在 6 月 16 日美国复活节时间上午 10:30 左右测试了相同的代码,并将到期日期设置为 6 月 17 日,并且由于 6 月 17 日凌晨 12 点,UTC 仍然比美国复活节时间上午 10:30 早足够多,因此它没有引发错误.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-30
    • 2012-10-23
    • 2011-01-01
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    相关资源
    最近更新 更多