Open dodyg opened 5 months ago
If you turn on debug logs, do you see a log saying "Unable to select a constructor. Multiple public constructors found for type 'RazorFormHandlingTwo.Pages.Index+Person'."
? That's what I expect should be logged from here.
I think we should probably relax this check to allow the use of the default constructor if multiple constructors are available. If we want to stick with the single constructor requirement, we should emit the "Multiple public constructors found" log with a higher severity like warning.
Yes
The problem is harder to figure out if you happen to use a nested object with multiple constructors.
public class DetailedName
{
public string FirstName { get; set;} = string.Empty;
public string LastName { get; set;} = string.Empty;
public DetailedName()
{
}
public DetailedName(string firstName)
{
FirstName = firstName;
}
}
public class Person
{
public DetailedName MoreNames { get; set; } = new();
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string Hobby { get; set; } = string.Empty;
public bool IsMarried { get; set; }
public string Nationality { get; set; } = string.Empty;
}
generates
Just a minor point here. As a workaround, I confirmed that non default constructors with parameters marked with an "internal" visibility make to pass this error generation.
Also agreed, it would be better if the default exception was more descriptive.
Is there an existing issue for this?
Describe the bug
will throw because
Person
class containspublic Person(string name)
constructor. If you remove it, it will work fine.Expected Behavior
It should just work fine as input
Steps To Reproduce
Person
class.Exceptions (if any)
.NET Version
8
Anything else?
No response