{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/3874","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/3874/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/3874/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/3874/events","html_url":"https://github.com/aspnet/Mvc/issues/3874","id":125162226,"number":3874,"title":"Null passed as arguments to controller method parameters when no InputFormatter matches","user":{"login":"bluemmc","id":12269205,"avatar_url":"https://avatars.githubusercontent.com/u/12269205?v=3","gravatar_id":"","url":"https://api.github.com/users/bluemmc","html_url":"https://github.com/bluemmc","followers_url":"https://api.github.com/users/bluemmc/followers","following_url":"https://api.github.com/users/bluemmc/following{/other_user}","gists_url":"https://api.github.com/users/bluemmc/gists{/gist_id}","starred_url":"https://api.github.com/users/bluemmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluemmc/subscriptions","organizations_url":"https://api.github.com/users/bluemmc/orgs","repos_url":"https://api.github.com/users/bluemmc/repos","events_url":"https://api.github.com/users/bluemmc/events{/privacy}","received_events_url":"https://api.github.com/users/bluemmc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-06T11:45:41Z","updated_at":"2016-01-07T17:55:41Z","closed_at":null,"body":"if the request's content-type is missing or not matching any InputFormatter then controller methods are passed null as arguments where data need to be deserialized. In the example below 'employee' is then null when the method is called. Instead the code 415 should be returned and the controller method should NOT be called.\r\n\r\n```public IActionResult UpdateEmployee(uint employeerId, [FromBody] Employee employee)```\r\n\r\nP.S:\r\nA workaround is to create a middleware the code below to force the error it is not very pretty and breaks if other content types than json is added because I am not aware how to check properly any of the registered InputFormatter's match rather then hardcoding it.\r\n\r\n```\r\n       async Task Invoke(HttpContext context)\r\n        {\r\n          string method = context.Request.Method;\r\n          if (method == \"PUT\" || method == \"POST\" || method == \"PATCH\")\r\n          {\r\n                RequestHeaders typedHeaders = context.Request.GetTypedHeaders();\r\n                MediaTypeHeaderValue contentType = typedHeaders.ContentType;\r\n                if (contentType==null || contentType.SubType!=@\"json\")\r\n                {\r\n                    context.Response.StatusCode = Status415UnsupportedMediaType;\r\n                    return;\r\n                }\r\n          }\r\n\r\n          await next.Invoke(context);\r\n        }\r\n```"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/169756097","html_url":"https://github.com/aspnet/Mvc/issues/3874#issuecomment-169756097","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/3874","id":169756097,"user":{"login":"bluemmc","id":12269205,"avatar_url":"https://avatars.githubusercontent.com/u/12269205?v=3","gravatar_id":"","url":"https://api.github.com/users/bluemmc","html_url":"https://github.com/bluemmc","followers_url":"https://api.github.com/users/bluemmc/followers","following_url":"https://api.github.com/users/bluemmc/following{/other_user}","gists_url":"https://api.github.com/users/bluemmc/gists{/gist_id}","starred_url":"https://api.github.com/users/bluemmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluemmc/subscriptions","organizations_url":"https://api.github.com/users/bluemmc/orgs","repos_url":"https://api.github.com/users/bluemmc/repos","events_url":"https://api.github.com/users/bluemmc/events{/privacy}","received_events_url":"https://api.github.com/users/bluemmc/received_events","type":"User","site_admin":false},"created_at":"2016-01-07T17:55:40Z","updated_at":"2016-01-07T17:55:40Z","body":"@rynowak I can not confirm this. I tried adding the consumes attribute to the base controller for all my controllers and it does not change the behavior. I still get null passed to the employee argument if content-type is missing for my PUT request to the update method UpdateEmployee."}}