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

Closed Issue: [HelpPage]Null ref exception when using UriPathExtensionMapping [1484]

$
0
0
_Scenario_:
I am trying to use UriPathExtensionMapping in my app so that I can request response in json or xml by using uri rather than accept header when i am using a browser.

_Issue_:
Help page UI shows a null ref exception as the route variable 'ext' doesn't have a HttpParameterDescriptor. But 'ext' would not have this descriptor because its not going to be used as a input parameter to a method.

_Repro_:
- Create a new 5.0 Web API template based project.
- Upgrade the HelpPage to latest 5.1
- Remove the default conventional route called "DefaultApi" from WebApiConfig.cs and just copy paste the following:
```
config.Routes.MapHttpRoute(
name: "DefaultApiWithExtension2",
routeTemplate: "api/{controller}/{id}.{ext}",
defaults: null,
constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
);

config.Routes.MapHttpRoute(
name: "DefaultApiWithExtension1",
routeTemplate: "api/{controller}.{ext}",
defaults: null,
constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) });

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);

config.Formatters.XmlFormatter.AddUriPathExtensionMapping("xml", "application/xml");
config.Formatters.JsonFormatter.AddUriPathExtensionMapping("json", "application/json");
```
- build and launch the app and go to helppage
- click any link related to actions you can perform on controller
- you should notice an error like below
```
Line 352: private static bool TryGetResourceParameter(ApiDescription apiDescription, HttpConfiguration config, out ApiParameterDescription parameterDescription, out Type resourceType)
Line 353: {
Line 354: parameterDescription = apiDescription.ParameterDescriptions.FirstOrDefault(p => p.Source == ApiParameterSource.FromBody || p.ParameterDescriptor.ParameterType == typeof(HttpRequestMessage));
Line 355:
Line 356: if (parameterDescription == null)

Source File: c:\Users\kichalla\Documents\Visual Studio 2013\Projects\WebApplication232\WebApplication232\Areas\HelpPage\HelpPageConfigurationExtensions.cs Line: 354
```

_Workaround_:
Conditional check for null in this piece of code.
Comments: Verified.

Viewing all articles
Browse latest Browse all 7215

Trending Articles