I am currently following the instructions at https://learn.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint
I am on step "Configure the OData endpoint". I encountered erroneous lines when I added the new code to the endpoint register method.
public static void Register(HttpConfiguration config)
{
// New code:
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: null,
model: builder.GetEdmModel());
}
I have tried all instructions (at config.MapODataServiceRoute error) to fix this. Using the suggestions on this site, I found many different ways to eliminate the line errors and get a successful build.
However, no matter which solution I use to get a successful build, when I run the service, I get the following error:
Server Error in '/' Application. Could not load file or assembly 'Microsoft.OData.Core, Version=7.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.OData.Core, Version=7.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
Line 12: protected void Application_Start() Line 13: { Line 14: GlobalConfiguration.Configure(WebApiConfig.Register); Line 15: }
Source File: C:\Users<username>\source\repos\ProductService\ProductService\Global.asax.cs Line: 14
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.OData.Core, Version=7.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileLoadException: Could not load file or assembly 'Microsoft.OData.Core, Version=7.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] Microsoft.AspNet.OData.Formatter.ODataMediaTypeFormatters.CreateApplicationJson() +0 Microsoft.AspNet.OData.Formatter.ODataMediaTypeFormatters.Create() +28 Microsoft.AspNet.OData.ODataFormattingAttribute.CreateODataFormatters() +5 Microsoft.AspNet.OData.ODataFormattingAttribute.Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) +280 System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type) +154 System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type) +54 System.Web.Http.Controllers.HttpControllerDescriptor..ctor(HttpConfiguration configuration, String controllerName, Type controllerType) +105 System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache() +400 System.Lazy
1.CreateValue() +429 System.Lazy
1.LazyInitValue() +158 System.Lazy1.get_Value() +79 System.Web.Http.Dispatcher.DefaultHttpControllerSelector.GetControllerMapping() +16 System.Web.Http.Routing.AttributeRoutingMapper.AddRouteEntries(SubRouteCollection collector, HttpConfiguration configuration, IInlineConstraintResolver constraintResolver, IDirectRouteProvider directRouteProvider) +48 System.Web.Http.Routing.<>c__DisplayClass1_1.<MapAttributeRoutes>b__1() +57 System.Web.Http.Routing.RouteCollectionRoute.EnsureInitialized(Func
1 initializer) +61 System.Web.Http.Routing.<>c__DisplayClass1_0.b__0(HttpConfiguration config) +91 System.Web.Http.HttpConfiguration.EnsureInitialized() +23 System.Web.Http.GlobalConfiguration.Configure(Action`1 configurationCallback) +43 ProductService.WebApiApplication.Application_Start() in C:\Users<username>\source\repos\ProductService\ProductService\Global.asax.cs:14[HttpException (0x80004005): Could not load file or assembly 'Microsoft.OData.Core, Version=7.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +475 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +220 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303
[HttpException (0x80004005): Could not load file or assembly 'Microsoft.OData.Core, Version=7.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +659 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +89 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4331.0