dotnet / dotnet/aspnetcore

Record struct model validation errors, and can't load record structs with defined empty constructor

Open
#40,934 1 comment 0 reactions 0 assignees View on GitHub
area-mvc feature-model-binding investigate Priority:1
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When try to define validations on top of record structs, if no constructor is present, the validation passes regardless of the actual validity of the model.
if an empty constructor is present, than application throws

### Expected Behavior

correct validations and no errors

### Steps To Reproduce


[RecordStructFails.zip](https://github.com/dotnet/aspnetcore/files/8372504/RecordStructFails.zip)

can run this, and see results

### Exceptions (if any)

invalid data still goes through,
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'RecordStructFails.RecordStructWithEmptyCtor'.

### .NET Version

net6.0

### Anything else?

vs 17.1.2
asp.net core 6

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.