In case if routeData contains null value of any key then RouteDataValueProvider thrown an exception NullReferenceException.
Fix:
yield return new KeyValuePair<string, string>(pair.Key, pair.Value != null ? pair.Value.ToString() : null);
-- source code --
public class RouteDataValueProvider : NameValuePairsValueProvider
{
public RouteDataValueProvider(HttpActionContext actionContext, CultureInfo culture)
: base(() => GetRoutes(actionContext.ControllerContext.RouteData), culture)
{
}
internal static IEnumerable<KeyValuePair<string, string>> GetRoutes(IHttpRouteData routeData)
{
foreach (KeyValuePair<string, object> pair in routeData.Values)
{
yield return new KeyValuePair<string, string>(pair.Key, pair.Value.ToString());
}
}
}
Fix:
yield return new KeyValuePair<string, string>(pair.Key, pair.Value != null ? pair.Value.ToString() : null);
-- source code --
public class RouteDataValueProvider : NameValuePairsValueProvider
{
public RouteDataValueProvider(HttpActionContext actionContext, CultureInfo culture)
: base(() => GetRoutes(actionContext.ControllerContext.RouteData), culture)
{
}
internal static IEnumerable<KeyValuePair<string, string>> GetRoutes(IHttpRouteData routeData)
{
foreach (KeyValuePair<string, object> pair in routeData.Values)
{
yield return new KeyValuePair<string, string>(pair.Key, pair.Value.ToString());
}
}
}