Use the actual Guid type rather than a string. You might also want to handle null.
[HttpGet("{id:Guid?}")]
public IActionResult Get(Guid? id)
{
return Ok(new { id = id ?? Guid.NewGuid() });
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello all of you
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?
Use the actual Guid type rather than a string. You might also want to handle null.
[HttpGet("{id:Guid?}")]
public IActionResult Get(Guid? id)
{
return Ok(new { id = id ?? Guid.NewGuid() });
}
Helllo.
Thanks for this information. Still not working.