Does not work in .net 6
See original GitHub issueI spent a full day trying to implement this library into an existing .net 6 application with no luck. I kept running into this error #157 and then a host of subsequent errors related to dependencies of IActionResultExecutor<ObjectResult> that were not registered. Upgrading to your latest nuget package 6.5.1 did not help. It added the registration for ObjectResultExecutor but none of its dependencies such as OutputFormatterSelector and IHttpResponseStreamWriterFactory. The dependency chain needed for this to work in a simple minimal api application is not there due the coupling to mvc. I was able to prove this by creating a brand new .net6 project, unchecking the option for controllers, and pasting your program.cs file from your minimal api example right in and running it. It fails on the builder.Build() line with this error:
System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor ‘ServiceType: Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor1[Microsoft.AspNetCore.Mvc.ObjectResult] Lifetime: Singleton ImplementationType: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor': Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.Infrastructure.OutputFormatterSelector' while attempting to activate 'Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor'.) ---> System.InvalidOperationException: Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultExecutor
1[Microsoft.AspNetCore.Mvc.ObjectResult] Lifetime: Singleton ImplementationType: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor’: Unable to resolve service for type ‘Microsoft.AspNetCore.Mvc.Infrastructure.OutputFormatterSelector’ while attempting to activate ‘Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor’.
—> System.InvalidOperationException: Unable to resolve service for type ‘Microsoft.AspNetCore.Mvc.Infrastructure.OutputFormatterSelector’ while attempting to activate ‘Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor’.
trucated for brevity
I tried adding these dependencies myself, but get stuck when adding one for IHttpResponseStreamWriterFactory since the class used by mvc is private and sealed. At that point I gave up. I am hoping you have some simple fix for this since I like your library. But honestly I think you may need to think about splitting your library, one for older mvc and the other for .net6+ minimal api and remove all mvc dependencies from it. The way things are going with .net6/7 much of what you have in your library is becoming obsolete or no longer the recommended best practice. Hope this helps guys.
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:7 (3 by maintainers)
Replacing
ObjectResultExecutor
withMinimalApiResultExecutor
will just bring back the problem I initially tried to solve (#180). I have an idea on how to fix this, but I need to do some experimentation. In the meantime, you can just revert back to v6.5.0, which uses theMinimalApiResultExecutor
.Having the same problem Im refactoring a new project from mvc to minimalapi. Any ETAs?