Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Issue: Model binding of route wildcard broken in Web API [718]

$
0
0
A route like this:

routes.MapHttpRoute(
"KuduVirtualFileSystem",
"api/{segment}/{*path}",
defaults: new { controller = "demo" });

and a Web Api controller action like this:

public async Task<HttpResponseMessage> GetItem(string segment, string path = null)

fails a request like this (no path component)

http:/..../api/segment

but works for a non-empty path component like this:

http:/.../api/segment/path

The exception is as follows:

{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":" at System.Web.Http.ValueProviders.Providers.RouteDataValueProvider.<GetRoutes>d__4.MoveNext()\r\n at System.Web.Http.ValueProviders.Providers.NameValuePairsValueProvider.InitializeValues(IEnumerable`1 nameValuePairs)\r\n at System.Web.Http.ValueProviders.Providers.NameValuePairsValueProvider.<>c__DisplayClass8.<.ctor>b__4()\r\n at System.Lazy`1.CreateValue()\r\n at System.Lazy`1.LazyInitValue()\r\n at System.Lazy`1.get_Value()\r\n at System.Web.Http.ValueProviders.Providers.NameValuePairsValueProvider.GetValue(String key)\r\n at System.Web.Http.ValueProviders.Providers.CompositeValueProvider.GetValue(String key)\r\n at System.Web.Http.ModelBinding.Binders.TypeConverterModelBinder.BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)\r\n at System.Web.Http.Controllers.HttpActionContextExtensions.Bind(HttpActionContext actionContext, ModelBindingContext bindingContext, IEnumerable`1 binders)\r\n at System.Web.Http.ModelBinding.Binders.CompositeModelBinder.TryBind(HttpActionContext actionContext, ModelBindingContext bindingContext)\r\n at System.Web.Http.ModelBinding.Binders.CompositeModelBinder.BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)\r\n at System.Web.Http.ModelBinding.ModelBinderParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Controllers.HttpActionBinding.<>c__DisplayClass1.<ExecuteBindingAsync>b__0(HttpParameterBinding parameterBinder)\r\n at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()\r\n at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)"}

Attached is a repro showing that it works in MVC and not in Web API

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>