2

我试图DeliveryClient在没有依赖注入的 Kentico Portal 项目中使用他们调用 Kentico Kontent。此项目希望迁移到 Kontent,但希望现有项目中的一个新功能在转换之前与 Kontent 一起实施。

安装 Kontent Delivery SDK 后,这是我的代码

var clientTest = DeliveryClientBuilder.WithProjectId("MyProjectId").Build();

我收到运行时错误

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.DependencyInjection, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.'

显然,这个项目没有依赖注入,我听说在门户项目中设置它是很困难的,如果不是不可能的话。因此,我决定按照 Kentico 的博客文章中所述新建自己的交付客户端

var test = new DeliveryClient(options);

DeliveryClient标记为内部:'DeliveryClient' is inaccessible due to its protection level

我该如何进行?

细节

  • Kentico.Kontent.Delivery 12.3.0
  • Kentico 版本 12.0.22
  • .Net 框架 4.6.1
4

2 回答 2

0

尽管Kentico.Kontent.Delivery 12.*目标netstandard2.0意味着它应该与 .NET Framework 4.6.1 兼容,但有证据表明此设置可能会导致问题。在尝试其他任何事情之前,我会推荐一些事情:

  1. 升级到 .NET 4.8(或至少到 4.7.2)
  2. 通过添加以下内容在您的项目中启用自动绑定重定向:
<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

无论您如何实例化/注册 DeliveryClient ( DeliveryClientBuilder services.AddDeliveryClient()),SDK 始终在Microsoft.Extensions.DependencyInjection内部使用,因此没有解决方法。您将需要解决程序集绑定问题。

于 2020-03-12T19:07:44.117 回答
0

实际问题要愚蠢得多。我已经在另一个项目中安装了 Kontent Delivery Client nuget sdk,并且只在这个项目中引用了它。为这个项目安装它解决了这个问题。我现在可以毫无错误地调用构建器。

于 2020-03-12T20:24:28.510 回答