Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No MediaTypeFormatter is available #102

Open
HamitEnes opened this issue Nov 6, 2020 · 0 comments
Open

No MediaTypeFormatter is available #102

HamitEnes opened this issue Nov 6, 2020 · 0 comments

Comments

@HamitEnes
Copy link

HamitEnes commented Nov 6, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant