I am attempting to call Kentico Kontent using their DeliveryClient
in a Kentico Portal project that doesn't have dependency injection. This project would like to migrate to Kontent but would like a new feature in the extisting project to be implemented with Kontent before the transition.
After installing the Kontent Delivery SDK, here's my code
var clientTest = DeliveryClientBuilder.WithProjectId("MyProjectId").Build();
I get a runtime error
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.'
Obviously, this project doesn't have dependency injection and I hear setting it up in a portal project is difficult if not impossible. So I decide to new up my own delivery client as outlined in Kentico's blog post
var test = new DeliveryClient(options);
But DeliveryClient
is marked internal: 'DeliveryClient' is inaccessible due to its protection level
How do I proceed?
Details
Although the Kentico.Kontent.Delivery 12.*
targets netstandard2.0
which means it should be compatible with .NET Framework 4.6.1 , there is evidence that this setup can cause issues. There are a few things that I would recommend before trying anything else:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
No matter how you instantiate/register the DeliveryClient ( DeliveryClientBuilder
services.AddDeliveryClient()
), the SDK always uses Microsoft.Extensions.DependencyInjection
internally, so there is no workaround. You will need to address the assembly binding problem.
The actual issue was much dumber. I had installed the Kontent Delivery Client nuget sdk in another project and only referenced it in this one. Installing it for this project solved the problem. I am able to call the builder without any errors now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.