In my dataservice (client-side) I try to call controller API with this (the Id 36fc1b86-9697-49c5-978c-825f465de73b is hard coded to show the problem) :
return await JsonSerializer.DeserializeAsync<IEnumerable<Stage>>
(
await _httpClient.GetStreamAsync($"api/stage/36fc1b86-9697-49c5-978c-825f465de73b"),
new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }
);
Server-side (API)
[HttpGet("{id}")]
public IActionResult GetAllStage(string id)
{
return Ok(_stageRepository.GetAllStagesById(id));
}
And the error :
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Value cannot be null. (Parameter 'source') System.ArgumentNullException: Value cannot be null. (Parameter 'source')
But if GUID starts with a letter (see below /a...) everything works #1 like this :
return await JsonSerializer.DeserializeAsync<IEnumerable<Stage>>
(
await _httpClient.GetStreamAsync($"api/stage/a0bdb087-dadc-4382-9a28-75f93917698b"),
new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
Workaround. I put a extra letter (here X) at the very begining :
return await JsonSerializer.DeserializeAsync<IEnumerable<Stage>>
(await _httpClient.GetStreamAsync($"api/stage/X{id}"), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
And remove it in the API...
[HttpGet("{id}")]
public IActionResult GetAllStage(string id)
{
return Ok(_stageRepository.GetAllStagesById(id.Remove(0, 1)));
}
Any idea about this bug?
nullto a method. You didn't post the full exception text so one can only guess where the problem may be, or what method was called. Quite likely the problem has nothing to do with the question's code