{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/3676","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/3676/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/3676/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/3676/events","html_url":"https://github.com/aspnet/Mvc/issues/3676","id":119964611,"number":3676,"title":"Model binding sometimes gives NREs","user":{"login":"Tragetaschen","id":1947968,"avatar_url":"https://avatars.githubusercontent.com/u/1947968?v=3","gravatar_id":"","url":"https://api.github.com/users/Tragetaschen","html_url":"https://github.com/Tragetaschen","followers_url":"https://api.github.com/users/Tragetaschen/followers","following_url":"https://api.github.com/users/Tragetaschen/following{/other_user}","gists_url":"https://api.github.com/users/Tragetaschen/gists{/gist_id}","starred_url":"https://api.github.com/users/Tragetaschen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tragetaschen/subscriptions","organizations_url":"https://api.github.com/users/Tragetaschen/orgs","repos_url":"https://api.github.com/users/Tragetaschen/repos","events_url":"https://api.github.com/users/Tragetaschen/events{/privacy}","received_events_url":"https://api.github.com/users/Tragetaschen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-12-02T15:21:16Z","updated_at":"2015-12-08T13:15:56Z","closed_at":null,"body":"I'm not sure what I'm seeing here, but my code definitely hasn't been reached yet.\r\n\r\nI have the following Action defined on a controller:\r\n```csharp\r\n[HttpPost(\"UploadForm\")]\r\npublic async Task<IActionResult> UploadForm([FromBody] JObject json)\r\n```\r\n\r\nWith rc1-final on Linux, my application can reach two states\r\n- Every request to this method succeeds\r\n- Every request to this method fails with\r\n```\r\n      An unhandled exception has occurred while executing the request\r\n      System.NullReferenceException: Object reference not set to an instance of an object\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.DefaultComplexObjectValidationStrategy+Enumerator.MoveNext () [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.ValidationVisitor.VisitChildren (IValidationStrategy strategy) [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.ValidationVisitor.VisitComplexType () [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.ValidationVisitor.Visit (Microsoft.AspNet.Mvc.ModelBinding.ModelMetadata metadata, System.String key, System.Object model) [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.ValidationVisitor.VisitChildren (IValidationStrategy strategy) [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.ValidationVisitor.VisitEnumerableType () [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.ValidationVisitor.Visit (Microsoft.AspNet.Mvc.ModelBinding.ModelMetadata metadata, System.String key, System.Object model) [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.ValidationVisitor.Validate (Microsoft.AspNet.Mvc.ModelBinding.ModelMetadata metadata, System.String key, System.Object model) [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.ModelBinding.Validation.DefaultObjectValidator.Validate (IModelValidatorProvider validatorProvider, Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary modelState, Microsoft.AspNet.Mvc.ModelBinding.Validation.ValidationStateDictionary validationState, System.String prefix, System.Object model) [0x00000] in <filename unknown>:0\r\n        at Microsoft.AspNet.Mvc.Controllers.DefaultControllerActionArgumentBinder+<BindModelAsync>d__6.MoveNext () [0x00000] in <filename unknown>:0\r\n[…unreadable async stack trace through the request pipeline]\r\n```"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/162876223","html_url":"https://github.com/aspnet/Mvc/issues/3676#issuecomment-162876223","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/3676","id":162876223,"user":{"login":"Tragetaschen","id":1947968,"avatar_url":"https://avatars.githubusercontent.com/u/1947968?v=3","gravatar_id":"","url":"https://api.github.com/users/Tragetaschen","html_url":"https://github.com/Tragetaschen","followers_url":"https://api.github.com/users/Tragetaschen/followers","following_url":"https://api.github.com/users/Tragetaschen/following{/other_user}","gists_url":"https://api.github.com/users/Tragetaschen/gists{/gist_id}","starred_url":"https://api.github.com/users/Tragetaschen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tragetaschen/subscriptions","organizations_url":"https://api.github.com/users/Tragetaschen/orgs","repos_url":"https://api.github.com/users/Tragetaschen/repos","events_url":"https://api.github.com/users/Tragetaschen/events{/privacy}","received_events_url":"https://api.github.com/users/Tragetaschen/received_events","type":"User","site_admin":false},"created_at":"2015-12-08T13:15:56Z","updated_at":"2015-12-08T13:15:56Z","body":"On further inspection (because `JProperty` doesn't have a `Key` property):\r\n\r\nWhen the code succeeds, this is the validation chain:\r\n```\r\nvalidation visitor (visit): Newtonsoft.Json.Linq.JObject\r\nvalidation visitor (enumerable): Newtonsoft.Json.Linq.JObject\r\nvalidation visitor (children): Newtonsoft.Json.Linq.JObject\r\nvalidation visitor (visit): Newtonsoft.Json.Linq.JProperty\r\nvalidation visitor (enumerable): Newtonsoft.Json.Linq.JProperty\r\nvalidation visitor (children): Newtonsoft.Json.Linq.JProperty\r\n```\r\n`JProperty` and `JObject` are both recognized as enumerable things, because they are.\r\n\r\nWhen things fail, the `JProperty` suddenly is a complex type:\r\n```\r\nvalidation visitor (visit): Newtonsoft.Json.Linq.JObject\r\nvalidation visitor (enumerable): Newtonsoft.Json.Linq.JObject\r\nvalidation visitor (children): Newtonsoft.Json.Linq.JObject\r\nvalidation visitor (visit): Newtonsoft.Json.Linq.JProperty\r\nvalidation visitor (complex): Newtonsoft.Json.Linq.JProperty\r\nvalidation visitor (children): Newtonsoft.Json.Linq.JProperty\r\n```\r\nAnd visiting the children tries to find a non-existing `Key` Property\r\n\r\nBut that means [`typeof(IEnumerable).IsAssignableFrom(ModelType)`](https://github.com/aspnet/Mvc/blob/9342cb0ab78add8c527edcbc4c0988edc96f01e3/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelMetadata.cs#L365) sometimes returns true and sometimes false for the same actual type.\r\n\r\n:tired_face: "}}