Skip to content
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

Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0 #92

Closed
JohanLarsson opened this issue Oct 8, 2018 · 7 comments

Comments

@JohanLarsson
Copy link
Member

JohanLarsson commented Oct 8, 2018

When using Microsoft.CodeAnalysis.Common 2.9

System.IO.FileLoadException : Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, 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)
   at System.Threading.Tasks.ValueTask`1.get_IsCompleted()
   at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<BuildDeclarationCompilationFromScratchAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<BuildCompilationInfoFromScratchAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<GetOrBuildCompilationInfoAsync>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<GetCompilationSlowAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Gu.Roslyn.Asserts.Analyze.GetDiagnostics(DiagnosticAnalyzer analyzer, Solution solution)
   at Gu.Roslyn.Asserts.AnalyzerAssert.CodeFix(DiagnosticAnalyzer analyzer, CodeFixProvider fix, DiagnosticsAndSources diagnosticsAndSources, String fixedCode, IEnumerable`1 suppressedDiagnostics, IEnumerable`1 metadataReferences, String fixTitle, AllowCompilationErrors allowCompilationErrors)
   at Gu.Roslyn.Asserts.AnalyzerAssert.CodeFix[TAnalyzer,TCodeFix](String codeWithErrorsIndicated, String fixedCode, String fixTitle, AllowCompilationErrors allowCompilationErrors)
   at Gu.Roslyn.Asserts.Tests.WithMetadataReferencesAttribute.AnalyzerAssertTests.CodeFixSingleClassOneErrorCorrectFix()
@JohanLarsson
Copy link
Member Author

For some reason pinning nuget System.Runtime.CompilerServices.Unsafe 4.5.1 solves the problem. Not sure why it is needed. From what I can see in the lock file latest version should be fine but no redirects are generated via <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

@jarzab3
Copy link

jarzab3 commented Dec 14, 2018

Hi @JohanLarsson ,
I have a the same issue with this assembly System.Runtime.CompilerServices.Unsafe with different Version=4.0.4.1
When you said pinning nuget System.Runtime.CompilerServices.Unsafe 4.5.1 what do you mean by this?
Thank you

@JohanLarsson
Copy link
Member Author

JohanLarsson commented Dec 14, 2018

With pin I meant specifying an exact version of the nuget package. Looks like this using paket.

nuget Microsoft.CodeAnalysis.CSharp.Workspaces 2.3.1
nuget System.Collections.Immutable 1.3.1
nuget System.Reflection.Metadata 1.4.2
nuget Microsoft.Composition 1.0.31
nuget System.Runtime.CompilerServices.Unsafe 4.5.1

@SimonSDA
Copy link

SimonSDA commented Feb 5, 2019

I had the same issue as above with the Unity 5.9.3 NuGet package - it seems the version now includes this System.Runtime.CompilerServices.Unsafe assembly, but the version it installs has no version info specified in the DLL. @JohanLarsson 's answer sorted it for me (in my case I added the 4.5.2 version of the package).

@ENikS
Copy link

ENikS commented Feb 15, 2019

@JohanLarsson @SimonSDA

So, reading this thread I got confused. Should it be version 4.5.1 or latest >=4.5.2 is fine?

@JohanLarsson
Copy link
Member Author

JohanLarsson commented Feb 15, 2019

Depends on Roslyn version I think. I've been unpinning with latest. Unpinning as in using latest version of both.

Here is a test project that uses latest of both: https://github.com/DotNetAnalyzers/PropertyChangedAnalyzers

The analyzer library is pinned to

nuget Microsoft.CodeAnalysis.CSharp.Workspaces 2.3.1
nuget System.Collections.Immutable 1.3.1
nuget System.Reflection.Metadata 1.4.2
nuget Microsoft.Composition 1.0.31
nuget System.Runtime.CompilerServices.Unsafe 4.5.1

It is using paket if it looks unfamiliar. I don't use nuget.exe much so can't help with that.

@kpbaranwal
Copy link

Installing version 4.5.1 of System.Runtime.CompilerServices.Unsafe worked for me too. I downgraded from 4.5.2 where I was getting the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants