I'm in the process of rewriting a legacy application using Dapper, WebAPI and HttpClientFactory to make DB calls. My development time has drastically been slowed down because I'm having to debug frequent 500 errors and I've been unable to understand what's causing them.
For example, I can get a list of events using this code:
return await JsonSerializer.DeserializeAsync<List<Event>>
(await _httpClient.GetStreamAsync($"api/Event/GetEvents"),
new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
However, this code- which is nearly identical to what I'm using to return the list of events- produces a 500 error:
return await JsonSerializer.DeserializeAsync<Event>
(await _httpClient.GetStreamAsync($"api/Event/GetEventDetail/{eventId}"),
new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
I broke that into two lines and found that this works:
var response = await _httpClient.GetStreamAsync($"api/Event/GetEventDetail/{eventId}");
return await JsonSerializer.DeserializeAsync<Event>(response);
Can anyone help me make sense of what's causing the error with the one-line solution?