kontent-ai / delivery-sdk-net

Kontent.ai Delivery .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Delivery
MIT License
32 stars 43 forks source link

Cannot create Delivery client with Builder #325

Closed Sevitas closed 2 years ago

Sevitas commented 2 years ago

Brief bug description

Exception is thrown when creating delivery client using a builder. DeliveryClientBuilder.WithProjectId(ProjectId)).Build();

same exception occurs for creating a client with a custom httpClient. DeliveryClientBuilder.WithProjectId(ProjectId).WithDeliveryHttpClient(new DeliveryHttpClient(httpClient)).Build();

stack trace: System.Reflection.ReflectionTypeLoadException Unable to load one or more of the requested types. Method 'get_Renditions' in type 'Kentico.Kontent.Delivery.ContentItems.Asset' from assembly 'Kentico.Kontent.Delivery, Version=16.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. Method 'FetchNextBatchAsync' in type 'Kentico.Kontent.Delivery.ContentItems.DeliveryItemsFeed'1' from assembly 'Kentico.Kontent.Delivery, Version=16.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeAssembly.get_DefinedTypes() at Scrutor.TypeSourceSelector.<>c.<InternalFromAssemblies>b__20_0(Assembly asm) at System.Linq.Enumerable.SelectManySingleSelectorIterator'2.MoveNext() at System.Linq.Enumerable.SelectEnumerableIterator'2.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator'2.MoveNext() at Scrutor.LifetimeSelector.Scrutor.ISelector.Populate(IServiceCollection services, RegistrationStrategy strategy) at Scrutor.ServiceTypeSelector.Scrutor.ISelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy) at Scrutor.ImplementationTypeSelector.Scrutor.ISelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy) at Scrutor.TypeSourceSelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy) at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.Populate(IServiceCollection services, ISelector selector, RegistrationStrategy registrationStrategy) at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.Scan(IServiceCollection services, Action'1 action) at Kentico.Kontent.Delivery.DeliveryServiceCollection..ctor() at Kentico.Kontent.Delivery.DeliveryJsonSerializer..ctor() at Kentico.Kontent.Delivery.Extensions.ServiceCollectionExtensions.RegisterDependencies(IServiceCollection services, Boolean isNamedRegistration) at Kentico.Kontent.Delivery.Extensions.ServiceCollectionExtensions.AddDeliveryClient(IServiceCollection services, DeliveryOptions deliveryOptions) at Kentico.Kontent.Delivery.Builders.DeliveryClient.DeliveryClientBuilderImplementation.Kentico.Kontent.Delivery.Builders.DeliveryClient.IDeliveryClientBuild.Build() at Kentico.Kontent.ModelGenerator.Tests.DeliveryCodeGeneratorTests.IntegrationTest_RunAsync_CorrectFiles() in C:\GIT\kontent-generators-net\test\Kentico.Kontent.ModelGenerator.Tests\DeliveryCodeGeneratorTests.cs:line 123 at Xunit.Sdk.TestInvoker'1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 264 --- End of stack trace from previous location --- at Xunit.Sdk.ExecutionTimer.AggregateAsync(Fun'1 asyncAction) in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48 at Xunit.Sdk.ExceptionAggregator.RunAsync(Func'1 code) in C:\Dev\xunit\xunit\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90

Expected behavior

Client is created and can be used.

MiroKentico commented 2 years ago

I tried to reproduce this in my small sample project and I was not able to. Also, build and run of tests from SDKs update for generators (https://github.com/Kentico/kontent-generators-net/pull/140) succeeded.

After discussion with @Sevitas, we treat this as some local development environment. I am closing this now.

Sevitas commented 2 years ago

The issue was caused by the invalid nuget cache. After clearing the nuget cache everything works just fine.