.Net Exception "Content type application/json does not have a factory registered to be parsed" using C# API Client
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
### What are you generating using Kiota, clients or plugins?
API Client/SDK
### In what context or format are you using Kiota?
Nuget tool
### Client library/SDK language
Csharp
### Describe the bug
Calling await client.Route.GetAsync throws and Exception "Content type application/json does not have a factory registered to be parsed".
I struggle to understand the Exception. I assume there is a problem deserializing the json response that returned from the server.
I hope you can clearify the problem and make it understandable for me.
Thanks in advance.
Btw - I am not sure if this ticket is actually a bug ... I think im just missing something using the client...
### Expected behavior
Content type application/json should have a factory registered.
Why is it not initialized within the client initialization? Return format should be known from openapi-spec.
### How to reproduce
I have generated a C#-ClientLibrary for the [Graphhopper API](https://docs.graphhopper.com/openapi) as shown below:
```
{
"applicationName": "application",
"apiDependencies": {
"GraphhopperApiClient": {
"apiDescriptionUrl": "c:\\Users\\klara\\Downloads\\openapi.json",
"apiDeploymentBaseUrl": "https://graphhopper.com/api/1/",
"requests": [
{
"method": "GET",
"uriTemplate": "route"
},
{
"method": "POST",
"uriTemplate": "route"
},
{
"method": "POST",
"uriTemplate": "matrix"
},
{
"method": "GET",
"uriTemplate": "matrix"
},
{
"method": "POST",
"uriTemplate": "vrp"
}
],
"extensions": {
"x-ms-kiota-hash": "6E7836590F7BEABE147D318372748B57AB692D213FE7C07A535B66F5FE789CE9",
"x-ms-kiota-version": "1.28.0"
}
}
}
}
```
I have imported the generated sources in my C# project and downloaded the required Kiota Dependencies using NuGet.
Application looks like this:
```
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Http.HttpClientLibrary;
using Microsoft.Kiota.Serialization.Json;
using System.Text.Json;
using static Lovion.Route.RouteRequestBuilder;
using static Microsoft.Kiota.Abstractions.Authentication.ApiKeyAuthenticationProvider;
async Task MainAsync() {
// AUTHENTICATION EXAMPLE
var apiKeyAdapter = new ApiKeyAuthenticationProvider("redacted", "X-API-Key", ApiKeyAuthenticationProvider.KeyLocation.QueryParameter);
var requestAdapter = new HttpClientRequestAdapter(apiKeyAdapter);
requestAdapter.BaseUrl = "https://klara:8989";
Lovion.GraphhopperApiClient client = new GraphhopperApiClient(requestAdapter);
// CALCULATE ROUTE EXAMPLE
Lovion.Models.RouteResponse route = await client.Route.GetAsync(q =>
{
q.QueryParameters.Point = ["50.58727,8.67554", "50.58727,7.67554"];
q.QueryParameters.Profile = "car";
});
}
await MainAsync();
```
### Open API description file
[openapi.json](https://github.com/user-attachments/files/21823857/openapi.json)
### Kiota Version
Should be 1.28.0
### Latest Kiota version known to work for scenario above?(Not required)
_No response_
### Known Workarounds
_No response_
### Configuration
- OS: Windows 11
- architecture: x64
### Debug output
Click to expand log
```
```
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.