3

I'm trying to consume Odata using Simple.Odata Client from a WPF Application.

Below is my code:

private async void button_Click(object sender, RoutedEventArgs e)
{
    V4Adapter.Reference();
    var client = new ODataClient("http://services.odata.org/V4/TripPinServiceRW/");
    var items = await client.FindEntriesAsync("Person");
}

When I run the application I'm getting an error:

Error:

Unable to load OData adapter from assembly Simple.OData.Client.V4.Adapter

Inner Exception:

{"Could not load file or assembly 'Microsoft.OData.Core, Version=6.15.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.OData.Core, Version=6.15.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}

Stack Trace:

at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) at Simple.OData.Client.ODataClient.d__91.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at SimpleOdataClient.MainWindow.d__1.MoveNext()

Note: The assembly Microsoft.OData.Core, is already added to project as a dependency.

I have noticed that the request is being sent to server and response is received. What could be the reason for above error? Could any one help me?

Rahul
  • 2,431
  • 3
  • 35
  • 77
  • I am in the same case, seems to be that my service is built for Microsoft.OData.Core 7.0 and the last Simple.OData does not support that version. – E-Bat Feb 22 '17 at 16:01

1 Answers1

0

I had the same issue with a freshly-installed Simple.OData.Client (version 6.0.1) from NuGet. Adding Simple.OData.Client.V4Adapter.Reference(); suggested in other posts didn't help. The solution which worked for me:

  1. When the exception is thrown, drill down through InnerException until you find LoaderException property
  2. Inside LoaderException check which versions of Microsoft.OData packages it is trying to load. In my case it was trying version 7.10.0.0 Inner exception

3. Check the version of Microsoft.OData packages you currently have. In my case it was running with version 7.9.4 for both Microsoft.OData.Edm and Microsoft.OData.Core. I updated both to 7.10.0 and it started to work.

PiotrS
  • 180
  • 3
  • 16