I am using Refit version 6.0.94. I have a .net 5.0 Api and a Blazor Server app .Net 5.0. The Api and Web app are both deployed in Linux containers. When running locally in visual studio (windows 10) I do not get the error.
The Get and Delete verbs are working fine, but the Patch and Post are failing with exception
System.Text.Json.JsonException: 'M' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0. ---> System.Text.Json.JsonReaderException: 'M' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0. at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) in //src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs:line 280 at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) in //src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs:line 1034
The Api Code is Here
[HttpPatch]
public async Task<IActionResult> PatchAsync([FromBody] Customer customer)
{
return Ok(await _service.PatchAsync(customer));
}
The Poco code as follows
namespace CustomerCare
{
public class Customer
{
[JsonPropertyName("Name")]
public string Name { get; set; }
[JsonPropertyName("Surname")]
public string Surname { get; set; }
[JsonPropertyName("Id")]
public int Id { get; set; }
[JsonPropertyName("SignupDate")]
public DateTime? SignupDate { get; set; }
}
}
Refit setup and definition
services.AddRefitClient<ICustomerService>().ConfigureHttpClient(c => c.BaseAddress = new Uri("http://myservername/api/v1"))
public interface ICustomerService
{
[Delete("/CustomerCare/")]
Task<bool> DeleteCustomer(int id);
[Patch("/CustomerCare/")]
Task<bool> PatchCustomerAsync([Body] Customer customer);
[Get("/CustomerCare/{id}")]
Task<Customer> GetCustomerByIdAsync(int id);
[Post("/CustomerCare/")]
Task PostAsync([Body] Customer customer);
}
The calling code is as follows
try
{
return await _customerService.PatchCustomerAsync(customer);
}
catch (ApiException ex)
{
var errors = await ex.GetContentAsAsync<Dictionary<string, string>>();
var message = string.Join("; ", errors.Values);
throw new Exception(message);
}