'How to return a http response with code 500 and a payload

I am currently trying to give my client more detailed error info from my backend. To do so I would like to send a response to their request that contains a string.

I tried this, but when I check the response in my client, the payload is empty:

(int, string) Error = (0,""); //is a Tuple
return new ObjectResult(Error.Item2) { StatusCode = 500, Value = Error };

I'm using dotnet core 3.1.415 and asp.netcore 3.1.21



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source