Could not load assembly 'Microsoft.Data.OData' when accessing Azure Storage during development
Asked Answered
A

4

5

I have created a simple C# application at visual studio and I try to run that from my local machine. I have visual studio 2013. However, when I try to run the program, I get the exception: Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral

I have also tried the solution mentioned here:Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0 error in Azure Cloud Worker Role using Table Storage

That is to add the following at my config file:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

But it still didn't work. I do not know if I should change anything at the versions of that text.

The line that throws the exception is:

    CloudTableClient client = storageAccount.CreateCloudTableClient();

I have also downloaded the package: http://www.nuget.org/packages/Microsoft.Data.Services.Client/ as mentioned at Missing Microsoft.Data.Services.Client version 5.6 on Azure Websites. However the installer informed me that I already have the version 5.6.1.0 of the file and nothing happens.

Microsoft.WindowsAzure.Storage.StorageException was unhandled   HResult=-2146233088   Message=Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.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=Microsoft.WindowsAzure.Storage   StackTrace:
       at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
       at Microsoft.WindowsAzure.Storage.Table.TableOperation.Execute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
       at Microsoft.WindowsAzure.Storage.Table.CloudTable.Execute(TableOperation operation, TableRequestOptions requestOptions, OperationContext operationContext)
       at UserConsoleProject2.Program.connectionAzureStorage() in c:\Users\user\Documents\Visual Studio 2013\Projects\UserConsoleProject2\UserConsoleProject2\Program.cs:line 42
       at UserConsoleProject2.Program.Main(String[] args) in c:\Users\user\Documents\Visual Studio 2013\Projects\UserConsoleProject2\UserConsoleProject2\Program.cs:line 419   InnerException: System.IO.FileLoadException
       HResult=-2146234304
       Message=Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.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=Microsoft.WindowsAzure.Storage
       FileName=Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
       FusionLog==== Pre-bind state information === LOG: DisplayName = Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35  (Fully-specified) LOG: Appbase = file:///C:/Users/user/Documents/Visual Studio 2013/Projects/UserConsoleProject2/UserConsoleProject2/bin/Debug/ LOG: Initial PrivatePath = NULL Calling assembly : Microsoft.WindowsAzure.Storage, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
=== LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\user\Documents\Visual Studio 2013\Projects\UserConsoleProject2\UserConsoleProject2\bin\Debug\UserConsoleProject2.exe.Config LOG: Using host configuration file:  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/user/Documents/Visual Studio 2013/Projects/UserConsoleProject2/UserConsoleProject2/bin/Debug/Microsoft.Data.OData.DLL. WRN: Comparing the assembly name resulted in the mismatch: Build Number ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

       StackTrace:
            at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpWebRequestFactory.BuildRequestForTableOperation(Uri uri, UriQueryBuilder builder, IBufferManager bufferManager, Nullable`1 timeout, TableOperation operation, Boolean useVersionHeader, OperationContext ctx, TablePayloadFormat payloadFormat, String accountName)
            at Microsoft.WindowsAzure.Storage.Table.TableOperation.<>c__DisplayClass18.<RetrieveImpl>b__15(Uri uri, UriQueryBuilder builder, Nullable`1 timeout, Boolean useVersionHeader, OperationContext ctx)
            at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ProcessStartOfRequest[T](ExecutionState`1 executionState, String startLogMessage)
            at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
       InnerException:

How can I make my program run?

Araldo answered 3/7, 2014 at 12:2 Comment(6)
Where are you trying to run the program - on your local machine while developing/testing or actually on Azure? Does it work in one and not the other?Lowson
Pleas post the code associated where the exception is being thrown.Lowson
What is your target framework in the Application properties? It should not be one that ends with Client Profile.Ciera
possible duplicate of Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0 error in Azure Cloud Worker Role using Table StorageLowson
@Lowson I have updated my question to include the line that produces the error. In addition I run the program from my local machineAraldo
@Lowson Yeah, I saw that question when I posted mine. I have the same problem, but the solution mentioned there does not work for me while it worked for the OP thereAraldo
G
6

I ran into the same problem. I got it to work by making sure I had the following libary versions installed from NuGet:

Microsoft.Windows.Azure.Configuration 2.0.0.0
Microsoft.Windows.Azure.Storage 4.1.0.0
Microsoft.Data.Edm 5.6.1.0
Microsoft.Data.OData 5.6.1.0
Microsoft.Data.Services.Client 5.6.1.0
System.Spatial 5.6.1.0

I then changed my app.config to contain the following:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Note that the referenced assemblies are version 5.6.1.0 while the app.config refers to 5.6.0.0. I don't know why this works.

Goldstone answered 8/7, 2014 at 16:31 Comment(2)
This worked for me, along with making sure Microsoft.Data.* dlls were at 5.6.0.0Braga
The difference is that one is the package version the other assembly version.Suffragist
U
2

Sometimes Visual Studio forgets to copy binaries from dependency projects. So, manually delete bin and obj folders and rebuild target project.

Uniflorous answered 8/7, 2019 at 11:34 Comment(0)
R
1

Seems the following part of code missing in your web.config

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
Rankins answered 3/7, 2014 at 12:7 Comment(5)
This is the solution that exist here: #16908884 but it mentions older versions than the version than the OP hasRedheaded
Thanks Ondipuli. I have tried that, but I couldn't make it work. Maybe if I change something at the versions will work. But I do not know what exactly.Araldo
You can try this. Try to reinstall Storage client libraries via Nuget. It will install the relevant dlls by default. Go to Visual Studio ->Tools-> Libarary Packet Manager - >Packet Manager Console -> PM> Install-Package WindowsAzure.StorageRankins
Can you try to change the version, by replacing the existing dependent assembly by this one <dependentAssembly> <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.1.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.1.0" /> </dependentAssembly>Rankins
I think, there is one more dependent assembly you have to add in your web.config to make this work. <dependentAssembly> <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.1.0" /> </dependentAssembly>Rankins
C
0

I had this issue with a .net core2.0 webjob, and could not find the answer (here or a blog etc) (this was not it, this would maybe work for pre core, but it gave me the clue)... but when I upgrade my Microsoft.Azure.webjobs and .Extentions to beta4 3.0.0 it resolved the issue - if this saves someone from 2 days of hell, great.

Chopin answered 2/2, 2018 at 1:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.