seesharper/LightInject

MissingMethodException - ASP.NET Core 2.1 Application Running Under .NET Full Framework

bt-Knodel opened this issue ยท 13 comments

Company uses an ASP.NET Core 2.1 application running under .NET Full Framework. Unfortunately, it seems that LightInject after 6.6.x is no longer compatible with this API. The exception is:

Exception Info: System.MissingMethodException at LightInject.Microsoft.DependencyInjection.PerRootScopeLifetime.RegisterForDisposal(System.Object) at LightInject.Microsoft.DependencyInjection.PerRootScopeLifetime.GetInstance(LightInject.GetInstanceDelegate, LightInject.Scope, System.Object[]) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(System.IServiceProvider, System.Type) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.IServiceProvider) at Microsoft.AspNetCore.Hosting.WebHostExtensions+<RunAsync>d__4.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(Microsoft.AspNetCore.Hosting.IWebHost) at Clients.Api.Program.Main(System.String[])

Tracking this down, it appears LightInject's package "LightInject.Microsoft.AspNetCore.Hosting". This package appears to look for an overload requiring the parameter to be IDisposable, but it's now an "object" since IAsyncDisposable support...

The first thing to try is to try a clean build. Secondly ensure that all LightInject dependencies are up to date.

ASP.NET Core 2.1 went out of support August 21, 2021 so I would recommend to upgrade to a supported version ๐Ÿ‘

@seesharper ASP.NET Core on the full framework is still actively supported by microsoft.

See section "ASP.NET Core 2.1 on .NET Framework" here: https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core

To help facilitate migrating applications to ASP.NET Core on .NET Core, the following ASP.NET Core 2.1 (latest patched version only) packages will be supported on the .NET Framework and follow the support cycle for those .NET Framework versions. ASP.NET Core 2.1 is defined as "Tools" in the Microsoft Support Lifecycle Policy. A "Tool" requires a minimum of 12 months notification prior to the end of support. For more information, please see this KB Article.

This was due to an upgrade to LightInject. I attempted to upgrade LightInject to version 6.6.x (all 6.6.x releases cause this issue) but it fails with ASP.NET Core 2.1 on full framework.

LightInject.Microsoft.AspNetCore.Hosting is running version 2.3.5, which is the latest version as well.

"ASP.NET Core on the full framework is still actively supported by microsoft."

Actually I did not know it was still possible ?

aspnet/Announcements#324

When you say .Net Full framework. What version are you using?

.NET Framework 4.7.2

Anyhows. There must be a binary mismatch somewhere in your dependencies. It is correct that the RegisterForDisposal has changed from IDisposable to object, but that should be okay if all LightInject related dependencies are up to date

I cleaned, rebuilt, and even sent this on to a completely rebuilt from scratch environment. All of those situations resulted in this same error.

Okay, I would need a repro project to debug this. I don't see where it could fail if all deps are up to date

Alright, I stood up a demo project, and it turns out it has to do with the version of LightInject.Microsoft.DependencyInjection... The solution uses 3.3.6 of that package, with the latest being 3.6.3.

Apologies, it was an indirect reference (not referenced by the API project directly), so you were definitely correct that the latest version of all LightInject packages solves this issue.

No problem. Glad you figured it out ๐Ÿ‘๐Ÿ˜€

Core2.1FullFramework.zip

Reproduction repo for future reference... Upgrading LightInject.Microsoft.DependencyInjection to 3.6.3 solves the issue. Thanks for helping narrow down the issue.