OData v4 error on start-up: Resource not found for the segment 'Whatever'

12,492

Solution 1

If this is happening on start-up then check that you have added your Customers model type to the model builder during start-up.

builder.EntitySet<CustomerModel>("Customers");

It sounds like the attribute mappings are being enumerated for the new controller but it cannot map the Customer model type back to an entity set.

Note: Q/A I figured this out almost immediately but I'm posting here because I'll probably do this again and forget what I did wrong!

Solution 2

This error happens in Web API attribute routing scenario. Web API attribute routing will check all ODataRouteAttributes for all found ODataControllers when running the initializer of HttpConfiguration.

You mentioned that the error happened after you added a new Model/entity, so I guess you maybe have two Edm Models:

ModelA, ModelB

And EntitySet "Customers" is only in one of the model, for example the ModelA.

Besides, you may have the following codes for the new added Model:

config.MapODataServiceRoute("...", "...", ModelB);

When start-up, Web API finds the attribute:

[ODataRoute("Customers")]
public IHttpActionResult Get()
{
 ...
}

but, Web API can't find the "Customers" entity set in ModelB.

I think you can fix it by putting all into one model.

Share:
12,492
Luke Puplett
Author by

Luke Puplett

Started out as a Windows PSS engineer for Microsoft UK, then built industrial scale automation solutions for banks before turning to application and systems programming on .NET and Azure.

Updated on July 26, 2022

Comments

  • Luke Puplett
    Luke Puplett almost 2 years

    I am building out my new v4 service and all was going well until I added a new controller for a new model/entity and got this error when starting the site up for a test run.

    The controller seems to be correctly coded, just like the others.

    The path template 'Customers' on the action 'GetFeed' in controller 'CustomersOData' is not a valid OData path template. Resource not found for the segment 'Customers'.

    What on Earth does that mean?