iText7:无法读取许可证密钥json文件



我正在尝试在我的Dot-Net应用程序(C#编程语言(中加载iText7的许可证文件。我已经使用下面提到的语法给出了json文件的正确路径。

LicenseKey.LoadLicenseFile(new FileStream(@"pathtofileiTextKey.json", FileMode.Open)); 

我得到的错误信息是:

Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at iText.License.Util.XmlWorker..ctor(Stream stream)
at iText.License.LicenseKey.LoadLicenseFileInternal(Stream licenseIs)
at iText.License.LicenseKey.LoadLicenseFile(Stream licenseIs)

我验证了JSON文件,它看起来还可以。

解决这个问题的任何帮助都将大有帮助。

从堆栈跟踪中可以看出,它正在尝试将文件解析为XML。

参见文档:

但是,如果您有JSON许可证密钥文件,请参阅iText 7.2.x的说明。

安装iText 7.2。

尽管有iText v7.2.4和iText,我还是遇到了同样的错误。许可。通过nuget软件包的基本v4.0.4。事实证明,我的解决方案也有一个旧版本的iText(通过导入的库(,并且使用的LoadLicenseFile方法来自那个旧库。

换句话说,请确保您正在调用的完全限定方法是iText。许可。基础许可证密钥。LoadLicenseFile

使用itext.licensing.basenuget包。itext7.licensekey不是正确的软件包。这是包裹链接。。https://www.nuget.org/packages/itext.licensing.base/

这是代码

using iText.Licensing.Base;
var licenseFilePath = @"C:itextiText7.x_license.json";
if (File.Exists(licenseFilePath))
{
LicenseKey.LoadLicenseFile(new FileInfo(licenseFilePath));
}

最新更新