Issue with replacing IObjectModelValidator
See original GitHub issueHi,
I followed your example on disabling validation (see: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-5.0) and noticed some strange side-behavior, e.g. model validation on classes was indeed disabled, but validation on action (method) parameters (f.e. passed by query) resulted in a bad request (HTTP 400)
In short: a POST with a model in the body functioned as documented, but a GET with query parameters didn’t.
the example code tested:
public class NullObjectModelValidator : IObjectModelValidator
{
public void Validate(ActionContext actionContext,
ValidationStateDictionary validationState, string prefix, object model)
{
}
}
… and …
services.AddSingleton<IObjectModelValidator, NullObjectModelValidator>();
Is this by design or indeed a bug?
TIA
Bert
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to register a custom IObjectModelValidator with The ...
1 Answer. I found the error by debugging the source of Asp.net MVC core, i was using the method tryAddSingleton instead of AddSingleton...
Read more >ASP.NET Core breaking changes for versions 3.0 and 3.1
The MemoryCacheOptions.CompactOnMemoryPressure property has been removed. Reason for change. Automatically compacting the cache caused problems.
Read more >Breaking changes in .NET Core 3.0
The MemoryCacheOptions.CompactOnMemoryPressure property has been removed. Reason for change. Automatically compacting the cache caused problems.
Read more >Dependency Injection - ASP.NET Core Documentation
NET Core provides a minimal feature set and is not intended to replace other containers. Sections: What is Dependency Injection?
Read more >Asp.net, MVC, Silverlight, WPF, WCF, WF - Page 3
Namely, as soon as model binding returns an objects tree an implementation of the “IObjectModelValidator” interface is retrieved through dependency injection ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@amoorthaemer , example in documentation is not correct, as it leaves model in unvalidated state, which doesn’t work at least with
[FromBody]
and[FromHeaders]
parameters.Validate body should look like that:
Thanks, I think @MaceWindu’s response should address this. I’ve removed the section from our doc article, it’s not something we would recommend for most users, so I’ll consider this issue resolved.