dotnet core 3.0 - Unable to create an instance from Microsoft.AspNetCore.Mvc.ModelBinding.BindingInfo
See original GitHub issueI am currently in the process of upgrading a simple project to dotnet core 3. This project has a number of unit tests, the majority against the controller/api layer using AutoFixture & xunit2.
After the upgrade everything is working EXCEPT the autofixture unit tests that attempt to create a controller. They fail with the following exception:
AutoFixture.ObjectCreationExceptionWithPath : AutoFixture was unable to create an instance from Microsoft.AspNetCore.Mvc.ModelBinding.BindingInfo because creation unexpectedly failed with exception. Please refer to the inner exception to investigate the root cause of the failure.
Request path: ****.Inventory.Api.Controllers.ProductCategoriesController controller ****.Inventory.Api.Controllers.ProductCategoriesController Microsoft.AspNetCore.Mvc.ControllerContext ControllerContext Microsoft.AspNetCore.Mvc.ControllerContext Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor ActionDescriptor Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor System.Collections.Generic.IList
1[Microsoft.AspNetCore.Mvc.Abstractions.ParameterDescriptor] Parameters System.Collections.Generic.IList
1[Microsoft.AspNetCore.Mvc.Abstractions.ParameterDescriptor] System.Collections.Generic.List1[Microsoft.AspNetCore.Mvc.Abstractions.ParameterDescriptor] System.Collections.Generic.IEnumerable
1[Microsoft.AspNetCore.Mvc.Abstractions.ParameterDescriptor] collection System.Collections.Generic.IEnumerable`1[Microsoft.AspNetCore.Mvc.Abstractions.ParameterDescriptor] Microsoft.AspNetCore.Mvc.Abstractions.ParameterDescriptor Microsoft.AspNetCore.Mvc.ModelBinding.BindingInfo BindingInfo Microsoft.AspNetCore.Mvc.ModelBinding.BindingInfo
Inner exception messages: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. System.ArgumentException: The type ‘System.Object’ must implement ‘Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinder’ to be used as a model binder. (Parameter ‘value’)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:6
Top GitHub Comments
I know this is closed but for other folks who run into this who arent using Xunit the fast (lazy) workaround is to do
Fixture.Customize<BindingInfo>(c => c.OmitAutoProperties());
– I’m sure there is a way to also fix bindingInfo if you need it but if you dont in your tests…Solved the problem with
OmitAutoProperties
:var controller = fixture.Build<SomeController>().OmitAutoProperties().Create()
;