-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Blazor] Models with "ValidateComplexTypeAttribute" give an error on the backend(server) #17316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting this issue. This seems to be a bug and we've assigned one of our team members to look into this based on its priority. |
This is a bit unfortunate, I hadn't anticipated using this attribute in code shared between Blazor and MVC. The a) We can require that the attribute does not appear in MVC. You could do this by cross-compiling for @SteveSandersonMS \ @danroth27 what do you think? |
Automatically no-opping seems reasonable given that once we move this into CoreFx it's just going to work. |
Is there any work around for this current? I just got all of my front end code validating properly only to find that my backend is error'd now. Should I disable backend validation for now and add it back in once this gets fixed? |
@knight1219 the change is shipping as part of the upcoming preview2 release. Outside of having different models on the server and the client, we don't have a very good recommendation as of yet. |
As the fix is going into preview, will it ship with the May update or get held until .Net 5 releases? Just want to get any work arounds into our company backlog and for when the fix release making sure it doesn't add any regressions when we go to update. |
Describe the bug
If I have a model that has property decorated with attribute [ValidateComplexType] it works on the Blazor WebAssembly App but I get an error (see below) when that same model is used on the backend (server/api)
To Reproduce
What steps can we follow to reproduce the issue?
Please run the app I have included in the attached file.
The app was generated in visual studio 2019 preview. (Blazor WebAssembly app with ASP.NET Core hosted)
BlazorAppBug1.zip
Got Exceptions? Include both the message and the stack trace
System.InvalidOperationException: ValidateComplexTypeAttribute can only used with ObjectGraphDataAnnotationsValidator.
at System.ComponentModel.DataAnnotations.ValidateComplexTypeAttribute.IsValid(Object value, ValidationContext validationContext)
at System.ComponentModel.DataAnnotations.ValidationAttribute.GetValidationResult(Object value, ValidationContext validationContext)
at Microsoft.AspNetCore.Mvc.DataAnnotations.DataAnnotationsModelValidator.Validate(ModelValidationContext validationContext)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.ValidateNode()
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitComplexType(IValidationStrategy defaultStrategy)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Visit(ModelMetadata metadata, String key, Object model)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitChildren(IValidationStrategy strategy)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitComplexType(IValidationStrategy defaultStrategy)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Visit(ModelMetadata metadata, String key, Object model)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Validate(ModelMetadata metadata, String key, Object model, Boolean alwaysValidateAtTopLevel)
at Microsoft.AspNetCore.Mvc.ModelBinding.ObjectModelValidator.Validate(ActionContext actionContext, ValidationStateDictionary validationState, String prefix, Object model, ModelMetadata metadata)
The text was updated successfully, but these errors were encountered: