simpleinjector / SimpleInjector.Integration.AspNetCore

MIT License
2 stars 3 forks source link

Fix missing Microsoft.Bcl.AsyncInterfaces for ServiceCollection project in NetsStandard 2.0 #6

Closed kvpt closed 3 years ago

kvpt commented 3 years ago

Hi,

After updating SimpleInjector.Integration.AspNetCore.Mvc.Core to the latest version (5.1.1), my net 5.0 project fail to start. I found that the root cause was that the package Microsoft.Bcl.AsyncInterfaces has been removed from SimpleInjector.Integration.AspNetCore project dependencies. The problem is that the only target of this project is NetStandard 2.0, so I added a NetStandard 2.1 target and reintroduce the Microsoft.Bcl.AsyncInterfaces for the NetStandard 2.0 target. I built the packages on my local machine for testing and the modification fix the issue.

dotnetjunkie commented 3 years ago

Can you be more specific? Doesn't it compile? If so, what is the compilation error and on what code? If it fails at runtime, please provide the full exception?

kvpt commented 3 years ago

It's a runtime exception of type FileNotFoundException when application start.

The message is

Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

And the stack trace is :

   at SimpleInjector.SimpleInjectorServiceCollectionExtensions.AddContainerDisposalOnShutdown(IServiceCollection services, SimpleInjectorAddOptions options)
   at SimpleInjector.SimpleInjectorServiceCollectionExtensions.AddSimpleInjector(IServiceCollection services, Container container, Action`1 setupAction)
   at Planning.Api.Configs.ContainerConfig.AddSimpleInjector(IServiceCollection services, SimpleInjectorDependencyInjector dependencyInjector) in D:\Workspace\Planning\Planning.Api\Configs\ContainerConfig.cs:line 19
   at Planning.Api.Startup.ConfigureServices(IServiceCollection services) in D:\Workspace\Hacksis\Alcis.Isatis\Sources\Planning\Planning.Api\Startup.cs:line 43
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Planning.Api.Program.<Main>d__8.MoveNext() in D:\Workspace\Planning\Planning.Api\Program.cs:line 23
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Planning.Api.Program.<Main>(String[] args)
dotnetjunkie commented 3 years ago

That's odd. Microsoft.Bcl.AsyncInterfaces should be pulled in automatically because the SimpleInjector package takes a dependency on Microsoft.Bcl.AsyncInterfaces.

But either way, I'm currently in the middle of the process of removing the Microsoft.Bcl.AsyncInterfaces dependency completely from all libraries (including the core library and ServiceCollection). My advice, for now, is to roll back to the previous version and wait until the v5.2 set of packages are available.

kvpt commented 3 years ago

Ok no problem. For now I will just add an explicit dependency to Microsoft.Bcl.AsyncInterfaces to my project, this fix the issue. So I can wait for a new version with a fix. In this case I close the PR. Thank you.