【问题标题】:Kentico Kontent DeliveryClient.Build in Kentico Portal could not load file or assembly Microsoft.Extensions.DependencyInjectionKentico 门户中的 Kentico Kontent DeliveryClient.Build 无法加载文件或程序集 Microsoft.Extensions.DependencyInjection
【发布时间】:2020-03-12 15:31:23
【问题描述】:

我试图在没有依赖注入的 Kentico Portal 项目中使用他们的DeliveryClient 调用 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 的blog post 中所述新建我自己的交付客户

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 Framework 4.6.1

【问题讨论】:

    标签: c# kentico kentico-kontent


    【解决方案1】:

    虽然Kentico.Kontent.Delivery 12.*netstandard2.0 为目标,这意味着should be compatible with .NET Framework 4.6.1,但evidence 可能会导致此设置出现问题。在尝试其他任何事情之前,我建议您做一些事情:

    1. 升级到 .NET 4.8(或至少升级到 4.7.2)
    2. 在您的项目中启用Automatic Binding Redirection,方法是添加:
    <PropertyGroup>
      <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
      <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    </PropertyGroup>
    

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多