{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/3738","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/3738/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/3738/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/3738/events","html_url":"https://github.com/aspnet/Mvc/issues/3738","id":121656504,"number":3738,"title":"NullReferenceException during model binding with optional query parameters in actions","user":{"login":"davenewza","id":6212830,"avatar_url":"https://avatars.githubusercontent.com/u/6212830?v=3","gravatar_id":"","url":"https://api.github.com/users/davenewza","html_url":"https://github.com/davenewza","followers_url":"https://api.github.com/users/davenewza/followers","following_url":"https://api.github.com/users/davenewza/following{/other_user}","gists_url":"https://api.github.com/users/davenewza/gists{/gist_id}","starred_url":"https://api.github.com/users/davenewza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davenewza/subscriptions","organizations_url":"https://api.github.com/users/davenewza/orgs","repos_url":"https://api.github.com/users/davenewza/repos","events_url":"https://api.github.com/users/davenewza/events{/privacy}","received_events_url":"https://api.github.com/users/davenewza/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-12-11T07:46:52Z","updated_at":"2015-12-30T06:12:50Z","closed_at":"2015-12-28T22:50:14Z","body":"There is an issue with the model binding of optional query parameters in actions. \r\n\r\n### Repro steps\r\n\r\nTake the following controller action for example:\r\n\r\n    [HttpGet]\r\n    [Route(\"api/test\")]\r\n    public IActionResult Get(string value = \"default value\")\r\n    {\r\n        return Ok(value);\r\n    }\r\n\r\nRequesting with `api/test?value=something` works as it should, returning with _something_ in the response body.\r\n\r\nRequesting with `api/test` will result in a `NullReferenceException` (detailed further below) as the framework tries to bind to the action.\r\n\r\n### project.json extract:\r\n\r\n    {\r\n        ...\r\n        \"dependencies\": {\r\n          \"Microsoft.AspNet.Mvc\": \"6.0.0-rc1-final\",\r\n          \"Microsoft.AspNet.Mvc.Core\": \"6.0.0-rc1-final\",\r\n          \"Microsoft.AspNet.Mvc.Abstractions\": \"6.0.0-rc1-final\",\r\n          \"Microsoft.AspNet.Server.Kestrel\": \"1.0.0-rc1-final\",\r\n          \"Microsoft.AspNet.Diagnostics\": \"1.0.0-rc1-final\",\r\n          \"Microsoft.AspNet.Authorization\": \"1.0.0-rc1-final\",\r\n          \"Microsoft.AspNet.Authentication.JwtBearer\": \"1.0.0-rc1-final\",\r\n          \"Microsoft.Extensions.PlatformAbstractions\": \"1.0.0-rc1-final\",\r\n          \"Microsoft.Extensions.Configuration\": \"1.0.0-rc1-final\",\r\n          \"Microsoft.Extensions.Configuration.Json\": \"1.0.0-rc1-final\",\r\n          \"Microsoft.Extensions.Configuration.EnvironmentVariables\": \"1.0.0-rc1-final\",\r\n          \"Newtonsoft.Json\": \"6.0.6\"\r\n        },\r\n        \"commands\": {\r\n          \"web\": \"Microsoft.AspNet.Server.Kestrel\"\r\n        },\r\n        \"frameworks\": {\r\n          \"dnx451\": { }\r\n        },\r\n    }\r\n\r\n### Exception\r\n\r\n > System.NullReferenceException: Object reference not set to an instance of an object.\r\n   at Microsoft.AspNet.Mvc.ModelBinding.CompositeModelBinder.<RunModelBinders>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Mvc.Controllers.DefaultControllerActionArgumentBinder.<BindModelAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Mvc.Controllers.DefaultControllerActionArgumentBinder.<PopulateArgumentsAsync>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Mvc.Controllers.DefaultControllerActionArgumentBinder.<BindActionArgumentsCoreAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAllActionFiltersAsync>d__52.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeExceptionFilterAsync>d__51.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAsync>d__44.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.<RouteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Mvc.Routing.InnerAttributeRoute.<RouteAsync>d__10.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ApplicationInsights.AspNet.RequestTrackingMiddleware.<Invoke>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Hosting.Internal.HostingEngine.<>c__DisplayClass32_0.<<Start>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.AspNet.Server.Kestrel.Http.Frame.<RequestProcessingAsync>d__79.MoveNext()"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/167943949","html_url":"https://github.com/aspnet/Mvc/issues/3738#issuecomment-167943949","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/3738","id":167943949,"user":{"login":"davenewza","id":6212830,"avatar_url":"https://avatars.githubusercontent.com/u/6212830?v=3","gravatar_id":"","url":"https://api.github.com/users/davenewza","html_url":"https://github.com/davenewza","followers_url":"https://api.github.com/users/davenewza/followers","following_url":"https://api.github.com/users/davenewza/following{/other_user}","gists_url":"https://api.github.com/users/davenewza/gists{/gist_id}","starred_url":"https://api.github.com/users/davenewza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davenewza/subscriptions","organizations_url":"https://api.github.com/users/davenewza/orgs","repos_url":"https://api.github.com/users/davenewza/repos","events_url":"https://api.github.com/users/davenewza/events{/privacy}","received_events_url":"https://api.github.com/users/davenewza/received_events","type":"User","site_admin":false},"created_at":"2015-12-30T06:12:50Z","updated_at":"2015-12-30T06:12:50Z","body":"Sorry, I reopened it mistakenly."}}