I'm currently learning how to create OData services with MS's ASP.NET web API guide . In the Helpers section, trying to grab the field HttpRequestMessage.ODataProperties().PathHandler or ...Model throws the above error. According to MS's documentation, the import System.Web.OData.Extensions should be right.
Working with 6.13.0 for Odata.Client and 7.0.0 for Odata.Core.
Relevant code, basically 1:1 with the web api guide:
using Microsoft.OData;
using Microsoft.OData.UriParser;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http.Routing;
using System.Web.OData.Extensions;
namespace WebApiGuide {
public static class Helpers
{
public static TKey GetKeyFromUri<TKey>(HttpRequestMessage Request, Uri uri)
{
if (uri == null)
{
throw new ArgumentNullException("uri");
}
var urlHelper = Request.GetUrlHelper() ?? new UrlHelper(Request);
string serviceRoot = urlHelper.CreateODataLink(
Request.ODataProperties().RouteName,
Request.ODataProperties().PathHandler, new List<ODataPathSegment>());
var odataPath = Request.ODataProperties().PathHandler.Parse(
Request.ODataProperties().Model,
serviceRoot, uri.LocalPath);
var keySegment = odataPath.Segments.OfType<KeyValuePathSegment>().FirstOrDefault();
if (keySegment == null)
{
throw new InvalidOperationException("The link does not contain a key");
}
var value = ODataUriUtils.ConvertFromUriLiteral(keySegment.Value, ODataVersion.V4);
return (TKey)value;
}
}
}
Edit: If it makes the issue any more specific, I have the same issue with KeyValuePathSegment which is in System.Web.OData.Routing