asp.net web api - WebApi 2 and OData controller - cast exception during route configuration, GetEdmModel not understood -


i have controller i've built (extending system.web.http.odata.odatacontroller) , think it's going work fine - it's based on pure scaffolding provided visual studio ide.

the application build, but, errors out during application start-up. when goes perform initial route configuration, fails on last line of webapiconfig class in app_start folder - call config.mapodataserviceroute throws invalidcastexception because value of builder.getedmmodel() isn't understood:

imports system.web.http imports system.web.http.cors imports system.web.http.odata.builder imports system.web.odata.extensions  public class webapiconfig     public shared sub register(byval config httpconfiguration)     ' web api configuration , services      'enable cross orgin scripting 'cors'     dim cors = new enablecorsattribute("*", "*", "*")     config.enablecors(cors)      ' web api routes     config.maphttpattributeroutes()      config.routes.maphttproute(         name:="defaultapi",         routetemplate:="api/{controller}/{id}",         defaults:=new {.id = routeparameter.optional}     )       dim builder new odataconventionmodelbuilder     builder.entityset(of businessorder)("businessorder")     config.mapodataserviceroute("odata", nothing, builder.getedmmodel())     end sub end class 

here's specific language of invalidcastexception:

unable cast object of type 'microsoft.data.edm.library.edmmodel' type 'microsoft.odata.edm.iedmmodel'. 

hmmm.. docs odataconventionmodelbuilder , mapodataserviceroute seem indicate i'm dealing compatible types. if read error right, i'm getting instance of microsoft.data.edm.library.edmmodel call getedmmodel, think ought conformant iedmmodel interface, per docs.

here's web application's nuget packages.config - helps understand libraries being referenced web app:

<?xml version="1.0" encoding="utf-8"?> <packages>   <package id="antlr" version="3.4.1.9004" targetframework="net45" />   <package id="entityframework" version="6.1.3" targetframework="net45" />   <package id="jquery" version="1.10.2" targetframework="net45" />   <package id="jquery.ui.combined" version="1.11.4" targetframework="net45" />   <package id="jquery.validation" version="1.11.1" targetframework="net45" />   <package id="knockoutjs" version="2.3.0" targetframework="net45" />   <package id="microsoft.aspnet.cors" version="5.2.3" targetframework="net45" />   <package id="microsoft.aspnet.mvc" version="5.2.3" targetframework="net45" />   <package id="microsoft.aspnet.odata" version="5.6.0" targetframework="net45" />   <package id="microsoft.aspnet.razor" version="3.2.3" targetframework="net45" />   <package id="microsoft.aspnet.web.optimization" version="1.1.3" targetframework="net45" />   <package id="microsoft.aspnet.webapi.client" version="5.2.3" targetframework="net45" />   <package id="microsoft.aspnet.webapi.core" version="5.2.3" targetframework="net45" />   <package id="microsoft.aspnet.webapi.cors" version="5.2.3" targetframework="net45" />   <package id="microsoft.aspnet.webapi.odata" version="5.5.1" targetframework="net45" />   <package id="microsoft.aspnet.webpages" version="3.2.3" targetframework="net45" />   <package id="microsoft.data.edm" version="5.6.0" targetframework="net45" />   <package id="microsoft.data.odata" version="5.6.0" targetframework="net45" />   <package id="microsoft.odata.core" version="6.11.0" targetframework="net45" />   <package id="microsoft.odata.edm" version="6.11.0" targetframework="net45" />   <package id="microsoft.spatial" version="6.11.0" targetframework="net45" />   <package id="microsoft.web.infrastructure" version="1.0.0.0" targetframework="net45" />   <package id="modernizr" version="2.6.2" targetframework="net45" />   <package id="newtonsoft.json" version="6.0.8" targetframework="net45" />   <package id="system.spatial" version="5.6.0" targetframework="net45" />   <package id="webgrease" version="1.5.2" targetframework="net45" /> </packages> 

you mixing versions of odata. namespace system.web.http.odata v3 , namespace system.web.odata v4.

imports system.web.http.odata.builder imports system.web.odata.extensions  

i don't know version trying use should consistent. try changing both http

imports system.web.http.odata.builder imports system.web.http.odata.extensions  

or both not have http

imports system.web.odata.builder imports system.web.odata.extensions  

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -