Could not load file or assembly 'Elasticsearch.Net' or one of its dependencies

1

I've recently upgraded from NEST 1.9 to NEST 2.3. From some reason the assemblies in .NET have not been updated and are still looking for ElasticSearch.net package Elasticsearch.Net, Version=1.0.0.0

I've tried uninstalling then installing ElasticSearch.net and then NEST after which I restarted Visual Studio 4.6. I use .NET 45.

Could not load file or assembly 'Elasticsearch.Net' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Elasticsearch.Net' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Elasticsearch.Net' could not be loaded.

=== Pre-bind state information === LOG: DisplayName = Elasticsearch.Net (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: Elasticsearch.Net | Domain ID: 2 WRN: A partial bind occurs when only part of the assembly display name is provided. WRN: This might result in the binder loading an incorrect assembly. WRN: It is recommended to provide a fully specified textual identity for the assembly, WRN: that consists of the simple name, version, culture, and public key token. WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. LOG: Appbase = file:///C:/wht/We Heart Tours/wht/ LOG: Initial PrivatePath = C:\wht\We Heart Tours\wht\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\wht\We Heart Tours\wht\web.config LOG: Using host configuration file: C:\Users\amocanu\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Users/amocanu/AppData/Local/Temp/Temporary ASP.NET Files/root/412255cb/fee8480d/Elasticsearch.Net.DLL. LOG: Attempting download of new URL file:///C:/Users/amocanu/AppData/Local/Temp/Temporary ASP.NET Files/root/412255cb/fee8480d/Elasticsearch.Net/Elasticsearch.Net.DLL. LOG: Attempting download of new URL file:///C:/wht/We Heart Tours/wht/bin/Elasticsearch.Net.DLL. LOG: Using application configuration file: C:\wht\We Heart Tours\wht\web.config LOG: Using host configuration file: C:\Users\amocanu\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Redirect found in application configuration file: 2.0.0.0 redirected to 1.0.0.0. LOG: Post-policy reference: Elasticsearch.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d LOG: Attempting download of new URL file:///C:/Users/amocanu/AppData/Local/Temp/Temporary ASP.NET Files/root/412255cb/fee8480d/Elasticsearch.Net.DLL. LOG: Attempting download of new URL file:///C:/Users/amocanu/AppData/Local/Temp/Temporary ASP.NET Files/root/412255cb/fee8480d/Elasticsearch.Net/Elasticsearch.Net.DLL. LOG: Attempting download of new URL file:///C:/wht/We Heart Tours/wht/bin/Elasticsearch.Net.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Stack Trace:

[FileLoadException: Could not load file or assembly 'Elasticsearch.Net' 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 'Elasticsearch.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

c#
.net-assembly
nest
asked on Stack Overflow Jan 28, 2017 by Adrian

2 Answers

1

In case it helps anyone,
the solution is to edit Web.config and change

   <assemblyIdentity name="Elasticsearch.Net" publicKeyToken="96c599bbe3e70f5d" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="1.0.0.0" />

to

   <assemblyIdentity name="Elasticsearch.Net" publicKeyToken="96c599bbe3e70f5d" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
answered on Stack Overflow Jan 28, 2017 by Adrian
0

This error normally happens when you have two Elasticsearch.Net dependencies with different versions. In my case, it happened because I imported the Serilog.Sinks.ElasticSearch package in a project which already had the Elasticsearch.Net and NEST packages. As Serilog.Sinks.ElasticSearch and NEST packages have Elasticsearch.Net as a dependency, they need to be in the same version. I updated the Elasticsearch.Net and NEST packages to solve this problem.

This was the .csproj configuration before:

<PackageReference Include="Serilog.Formatting.Elasticsearch" Version="8.2.0" />
<PackageReference Include="NEST" Version="7.0.1" />
<PackageReference Include="Elasticsearch.Net" Version="7.0.1" />

This is the solution:

<PackageReference Include="Serilog.Formatting.Elasticsearch" Version="8.2.0" />
<PackageReference Include="NEST" Version="7.9.0" />
<PackageReference Include="Elasticsearch.Net" Version="7.9.0" />    

It's important to check the NuGet reference to get information about the imported package dependencies: https://www.nuget.org/packages/Nest , https://www.nuget.org/packages/Serilog.Sinks.ElasticSearch , https://www.nuget.org/packages/Elasticsearch.Net .

answered on Stack Overflow Sep 17, 2020 by Luiz Lelis • edited Sep 18, 2020 by Joe Mayo

User contributions licensed under CC BY-SA 3.0