1

Closed

error with odata query

description

hi, i just created a new project adding the daily build packages from myget.
i created a web api controller, using entities created from reverse engineering a db using ef power tools.

this it the code in the apicontroller
    private attivitaContext db = new attivitaContext();

    // GET api/cliente
    [Queryable]
    public IQueryable<Cliente> Get()
    {
        db.Configuration.LazyLoadingEnabled = false;
        return db.Clienti;
    }
if i calli api/cliente it works fine, when i add paramters as
http://localhost:26995/api/cliente?$filter=Attivo eq true&$orderby=Descrizione i receive this error {"Message":"An error has occurred.","ExceptionMessage":"The type 'WebIntf.Models.Cliente' cannot be configured as a ComplexType. It was previously configured as an EntityType.\r\nParameter name: type","ExceptionType":"System.ArgumentException","StackTrace":" at System.Web.Http.OData.Builder.ODataModelBuilder.AddComplexType(Type type)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.AddComplexType(Type type)\r\n at System.Web.Http.OData.Builder.StructuralTypeConfiguration.AddComplexProperty(PropertyInfo propertyInfo)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.MapComplexType(IComplexTypeConfiguration complexType)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.AddComplexType(Type type)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.RediscoverComplexTypes(IEnumerable1 explicitlyAddedTypes)\r\n at System.Web.Http.OData.Builder.ODataConventionModelBuilder.GetEdmModel()\r\n at System.Web.Http.HttpActionDescriptorExtensions.<>c__DisplayClass1.b__0(Object _)\r\n at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)\r\n at System.Web.Http.HttpActionDescriptorExtensions.GetEdmModel(HttpActionDescriptor actionDescriptor, Type entityClrType)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.b__0(HttpResponseMessage response)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass412.b__40(Task1 t)\r\n at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)"}

how can i fix?
Closed Aug 28, 2012 at 2:23 AM by raghuramn

comments

raghuramn wrote Aug 24, 2012 at 5:17 PM

which build are you using ? This should be fixed in 0.1.0-alpha-120824.

lucamorelli wrote Aug 24, 2012 at 5:36 PM

at the moment i see the 120823 in nuget, i'll try later and check

lucamorelli wrote Aug 24, 2012 at 5:52 PM

updated, now when i try to run i obtain the message

[FileLoadException: Could not load file or assembly 'Microsoft.Data.Edm' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or assembly 'Microsoft.Data.Edm, Version=5.0.2.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.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

the version installed is the 5.0.1

lucamorelli wrote Aug 24, 2012 at 6:03 PM

i found this in web.config
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.0.2.0" newVersion="5.0.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.0.2.0" newVersion="5.0.2.0" />
  </dependentAssembly>
but both the dll are version 5.01

raghuramn wrote Aug 24, 2012 at 6:23 PM

not sure how you got 5.0.1 version of Microsoft.Data.Edm. Nuget generally installs the latest version avaiable which is 5.0.2. you can either upgrade Microsoft.Data.Edm and System.Spatial to 5.0.2 or remove the assembly binding redirects.

lucamorelli wrote Aug 24, 2012 at 8:53 PM

thanks, uninstalled odata and reinstalled and now works

raghuramn wrote Aug 24, 2012 at 9:29 PM

Great. Could you please close the issue ? Thanks.

lucamorelli wrote Aug 25, 2012 at 7:51 AM

how can i close it? i don't see any command to do this.

lucamorelli wrote Aug 25, 2012 at 11:19 AM

btw: i think I understood the problem of the strange version: enabling the include prerelease, even if i have already installed the of EdmLib 5.0.2rc, 5.0.1 OdataLib,System.Spatial, 5.02 rc, in the prerelease updates from the nuget official feed i have the 5.1.0rc1 version of these packages.
if this is of help

raghuramn wrote Aug 28, 2012 at 2:22 AM

closing this as the customer confirmed that this is working. Thanks lucamorelli.

dauciunas wrote Oct 15, 2012 at 3:55 PM

I'm also getting the error of "...cannot be configured as a ComplexType. It was previously configured as an EntityType"

How Do I get my hands on this 0.1.0-alpha-120824 ?
NuGet is still getting the 120815 version



PM> Install-Package Microsoft.AspNet.WebApi.OData -Pre
Attempting to resolve dependency 'Microsoft.Net.Http (≥ 2.0.20710.0 && < 2.1)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (≥ 4.0.20710.0 && < 4.1)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 4.5.6)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (≥ 4.0.20710.0 && < 4.1)'.
Attempting to resolve dependency 'Microsoft.Data.OData.Contrib (= 5.0.1.50813)'.
Attempting to resolve dependency 'Microsoft.Data.OData (= 5.0.1)'.
Attempting to resolve dependency 'System.Spatial (≥ 5.0.1)'.
Attempting to resolve dependency 'Microsoft.Data.Edm (≥ 5.0.1)'.
'Microsoft.AspNet.WebApi.OData 0.1.0-alpha-120815' already installed.
AccountService.Web already has a reference to 'Microsoft.AspNet.WebApi.OData 0.1.0-alpha-120815'.

raghuramn wrote Oct 15, 2012 at 10:00 PM

you can get the nightly builds with the fix. More about how to use the nightly builds at http://blogs.msdn.com/b/henrikn/archive/2012/04/29/using-nightly-nuget-packages-with-asp-net-web-stack.aspx