-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1' after upgrading from NEST 7.11 to 7.14 #5939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @appbbs. Thanks for raising this. I've narrowed it down to this performance improvement PR #5731. It depends on When I create a new .NET 4.8 app with NEST included, Unfortunately, this is really a bug in the framework and the package that you're running into. We have some options such as removing this fix (and reference) entirely for .NET Fx or looking at manually raising the dependency by also referencing System.Runtime.CompilerServices.Unsafe. Both are not ideal options as this will generally not affect consumers until they run into a conflict. This issue also affected some of the StackOverflow packages and Nick wrote up a useful post explaining the issue and some potential workarounds you could try. Would you mind letting me know if any of those help in your case? |
Hi @stevejgordon . Thanks for the reply. I double checked and find that System.Runtime.CompilerServices.Unsafe 5.0.0 is used by System.Diagnostics.DiagnosticSource: |
Hi @appbbs. I don't think it's quite so simple, unfortunately. For now, I'd rather see if I can reproduce this state of affairs and/or we can provide guidance on dealing with the rather annoying case of glitchy packages and binding redirect behaviour. In a brand new .NET 4.8 project, after adding
And this is the default
I suspect it's that binding redirect that is avoiding the issue in this simple console app. Would you be able to try updating your project to see if that helps as a potential workaround? Additionally, would you be able to share details of any other packages you depend on, the project type and share your own |
Hi @appbbs. I just wanted to follow up on my queries above.
|
I have the same issue without any uprgrades. I started my work with Elastic from 7.14 version. I'm receiving this exception when I'm turning debug mode on
Exception will be fired at the moment of index deletion:
If I comment initialization of debug mode -> exception will be gone |
@VaDRo Thanks for providing this information. Are you able to confirm your .NET runtime version please, and if possible, share details of any other packages your project references? Does the binding redirect mentioned above prevent the exception from occurring? |
Good day,Steve.
|
In case it helps anyone: we were getting the same error upgrading elastic search to 7.16. in our .NET project. The trouble was that we were referencing the elastic and nest libraries in one of our libraries, and then referencing our library in the main executable project. In this case the binding redirect needs to be in the main executable project config, not in the library's config. Also, it seems advisable to add a reference to the "System.Runtime.CompilerServices.Unsafe.dll" to the main executable project if you use automatic building, otherwise msbuild may not copy it to the output directory. |
Binding redirects in general are a bit broken in .NET Framework as we've touched on in this thread. I don't believe there's much we can do in the client library to resolve this, beyond the workarounds already highlighted. I'm going to close this on that basis. |
NEST/Elasticsearch.Net version: 7.14.0
Elasticsearch version: 7.3.2
.NET runtime version: 4.8
Operating system version: Windows Server 2019
Description of the problem including expected versus actual behavior:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'PerTypeValues
1' threw an exception. Source=Elasticsearch.Net StackTrace: at Elasticsearch.Net.Extensions.NameValueCollectionExtensions.ToQueryString(NameValueCollection nv) at Elasticsearch.Net.RequestData.CreatePathWithQueryStrings(String path, IConnectionConfigurationValues global, IRequestParameters request) at Elasticsearch.Net.RequestData..ctor(HttpMethod method, String path, PostData data, IConnectionConfigurationValues global, IRequestParameters local, IMemoryStreamFactory memoryStreamFactory) at Elasticsearch.Net.Transport
1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)at Nest.ElasticClient.Search[TDocument](ISearchRequest request)
Inner Exception 1:
FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Steps to reproduce:
1.
2.
3.
Expected behavior
It should not ask for System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1 but use Version=5.0.0
Provide
ConnectionSettings
(if relevant):Provide
DebugInformation
(if relevant):The text was updated successfully, but these errors were encountered: