When I run a action in my ASP.NET Core app debugger, I get this error:
The program has exited with code -1073741819 (0xc0000005).
My Action is this but never run in app:
[HttpPost]
public async Task<IActionResult> Create(RoleCUViewModel model)
{
//Do Some thing
}
And My ViewModel
is this:
public class RoleCUViewModel
{
[Required]
public string? Name
{
get => Name;
set
{
if (value != "Admin")
{
Name = value;
}
else Name = null;
}
}
public string? Description { get; set; }
}
I delete Authorize
attribute and test in Action
but my problem not solved.
My IDE is VS Code and my application framework is .NET 7.0.
How can I fix this error?
According to the error message The program has exited with code -1073741819 (0xc0000005).
, and I found it's code issue, the getter for Name
is recursively calling itself without any exit condition, leading to a stack overflow.
public class RoleCUViewModel
{
private string? _name;
[Required]
public string? Name
{
get => _name;
set
{
if (value != "Admin")
{
_name = value;
}
else _name = null;
}
}
public string? Description { get; set; }
}