A component of ASP.NET for creating RESTful web services that support HTTP-based communication between clients and servers.
Hi @Falanga, Rod, DOH ,
Thanks for reaching out.
What’s actually happening isn’t that your bool is magically turning into a ValueKind. The issue comes from using object as the type of Result.
When your Minimal API (in ASP.NET Core) returns the response, it gets serialized to JSON using System.Text.Json. Because Result is declared as object, the serializer doesn’t preserve the concrete type information.
On the Blazor side (Blazor), when that JSON is deserialized, Result becomes a JsonElement instead of a bool. Inside JsonElement, there’s a ValueKind property that describes what kind of JSON value it is (True, False, Number, etc.). That’s why you’re seeing errors mentioning ValueKind, you’re not actually holding a bool anymore, you’re holding a JSON wrapper.
Instead of using object, switch to a strongly typed generic response:
public class APIResponse<T>
{
public bool IsSuccess { get; set; }
public T Result { get; set; }
public HttpStatusCode StatusCode { get; set; }
public List<string> ErrorMessages { get; set; } = new();
}
Then return:
return new APIResponse<bool>
{
IsSuccess = true,
Result = true,
StatusCode = HttpStatusCode.OK
};
And in Blazor:
var response = await httpClient.GetFromJsonAsync<APIResponse<bool>>("your-endpoint");
bool value = response.Result;
Now the type stays consistent end-to-end. No JsonElement, no ValueKind, no casting gymnastics.
Using object in API DTOs tends to cause exactly this kind of issue because JSON serialization loses the concrete type. Generics keep everything strongly typed and predictable.
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.