Skip to content

No MediaTypeFormatter is available #102

@HamitEnes

Description

@HamitEnes

Hello,

I Have aspnet webapi project .Net Framework 4.6.1 and installed below nuget package.

'package id="Marvin.JsonPatch" version="2.1.1" targetFramework="net461" '

I have an ODataController and Patch method with HttpPatch attribute

public class SalesInvoicesController : Microsoft.AspNet.OData.ODataController
{
[System.Web.Http.HttpPatch]
public IHttpActionResult Patch([FromODataUri] int key, [FromBody] JsonPatchDocument'SalesInvoice' salesInvoicePatch)
{
// get the expense from the repository
SalesInvoice existingSalesInvoice = ....

            // apply the patch document 
            salesInvoicePatch.ApplyTo(existingSalesInvoice);
    }

}

using POSTMAN for example request either application/json or application/json-patch+json content-type request fail with this exception. I couldn't find any info in readme about that.

Exception thrown: 'System.Net.Http.UnsupportedMediaTypeException' in System.Net.Http.Formatting.dll No MediaTypeFormatter is available to read an object of type 'JsonPatchDocument`1' from content with media type 'application/json-patch+json'.

request body like that,

[
{
"op": "replace",
"path" : "/DocumentNo",
"value" : "A-303030"
}
]

response http 415 Unsupported Media Type

Additional Info : I added this part of code to my app start from one of closed issues

        config.Formatters.JsonFormatter.SupportedMediaTypes.Add(
            new MediaTypeHeaderValue("application/json-patch+json"));

How can I solve that? Thanks

Is there any additional setup for usage this nuget?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions