从外部应用程序查询 Kentico 博客文章时,是什么原因导致 "Object type 'cms.licensekey' not found" 异常?

What causes "Object type 'cms.licensekey' not found" exceptions when querying Kentico blog posts from an external application?

从外部(桌面)应用程序查询 Kentico 8 博客文章时,出现异常:

[ObjectQueryBase.Object]: Object type 'cms.licensekey' not found.

我可以毫无问题地查询页面、站点设置等。

代码:

CMSApplication.Init();
DataSet posts = BlogHelper.GetBlogPosts(siteName, aliasPath, null, true, null, null, true);

v8.1 和 v8.2 中修复了几个与博客和许可相关的错误,因此我建议对 v8.x 的最新修补程序进行修补程序,以帮助缓解您遇到的任何问题。

转到 DevNet 并在 Fixed bugs for v8 中搜索 "Blog",您将看到这些问题。

此错误意味着 Kentico 无法初始化包含 cms.licensekey 对象类型定义的模块。在这种情况下,我们讨论的是 CMS.LicenseProvider.dll 程序集中包含的许可模块。

这通常是由于无法定位 DLL 本身或其依赖项之一(或其依赖项,递归地)造成的。

在 Kentico 10 中,依赖项是:

  • CMS.Core
  • CMS.Base
  • CMS.DataEngine
  • CMS.Helpers
  • CMS.IO
  • CMS.EventLog
  • CMS.MacroEngine
  • Mono.Cecil

您必须确保所有这些(当然还有 CMS.LicenseProvider 本身)都存在于您应用程序的 bin 文件夹中。

但是有一个 更好的方法 - 你可以使用 Kentico.Libraries NuGet package and it'll bring in all the necessary dependencies for you. Follow the documentation.