microsoft / qsharp-compiler

Q# compiler, command line tool, and Q# language server
https://docs.microsoft.com/quantum
MIT License
682 stars 171 forks source link

Language server can't load project references after upgrade to .NET Core 3.1.400 #558

Closed bamarsha closed 4 years ago

bamarsha commented 4 years ago

Describe the bug

When opening a Q# project in Visual Studio Code or Visual Studio, the language server outputs errors and is unable to load project references:

image

[Info  - 14:24:15] workspace folder: c:\Users\samarsha\Desktop\QsProject
[Error - 14:24:16] MSBuild error in C:\Program Files\dotnet\sdk\3.1.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(59,5): Unerwarteter Fehler bei der ProcessFrameworkReferences-Aufgabe.
System.IO.FileNotFoundException: Could not load file or assembly 'NuGet.Frameworks, Version=5.7.0.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Das System kann die angegebene Datei nicht finden.
File name: 'NuGet.Frameworks, Version=5.7.0.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

[Error - 14:24:16] Failed to restore project 'c:\Users\samarsha\Desktop\QsProject\QsProject.csproj'.
[Error - 14:24:16] MSBuild error in C:\Program Files\dotnet\sdk\3.1.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(59,5): Unerwarteter Fehler bei der ProcessFrameworkReferences-Aufgabe.
System.IO.FileNotFoundException: Could not load file or assembly 'NuGet.Frameworks, Version=5.7.0.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Das System kann die angegebene Datei nicht finden.
File name: 'NuGet.Frameworks, Version=5.7.0.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

[Error - 14:24:16] Failed to resolve assembly references for project 'c:\Users\samarsha\Desktop\QsProject\QsProject.csproj'.
Discovered Q# project 'c:\Users\samarsha\Desktop\QsProject\QsProject.csproj'.
Loading project 'c:\Users\samarsha\Desktop\QsProject\QsProject.csproj'.
Done loading project 'c:\Users\samarsha\Desktop\QsProject\QsProject.csproj'

System information

Additional context

Reported first by @iitaiy: https://github.com/microsoft/qsharp-compiler/issues/556#issuecomment-670195256

bamarsha commented 4 years ago

@bettinaheim, I think you are familiar with something like this that happened before?

Gambero81 commented 4 years ago

I have the same problem after update .NET Core to 3.1.4 "Could not load file or assembly 'NuGet.Frameworks, Version=5.7.0.7"

in the "C:\Program Files\dotnet\sdk\3.1.401" folder i have this NuGet.Frameworks.dll:

image

bamarsha commented 4 years ago

Hi @Gambero81, our current plan is to include a fix for this bug in the next release at the end of August. The pull request for that is #566.

Unfortunately, in the meantime, I think the only solution is to downgrade .NET Core to the last 3.1.3xx release (3.1.302).

Gambero81 commented 4 years ago

Hi @samarsha , the issue is not only in qsharp-compiler where you applied the fix.

I use roslyn libraries to analize source code and i need to use MSBuildLocator.RegisterDefaults() so i tried the fix:

VisualStudioInstance vsi = MSBuildLocator.RegisterDefaults(); AssemblyLoadContext.Default.Resolving += (assemblyLoadContext, assemblyName) => { string path = Path.Combine(vsi.MSBuildPath, assemblyName.Name + ".dll"); if (File.Exists(path)) { return assemblyLoadContext.LoadFromAssemblyPath(path); } return null; };

but it not solve for me.. the method LoadFromAssemblyPath throw an exception because the assembly version trying to load does not match the version requested

ricardo-espinoza commented 4 years ago

Hi @Gambero81 ,

This issue was opened to track the error above on the Q# Compiler Language Server during initialization. With the fix that Sarah mentioned above, we're now able to start correctly after an upgrade to the SDK v3.1.400.

Are you encountering the problem above in a project unrelated to qsharp-compiler? If that's the case, then you might be interested in following the discussion on the original issue that motivated this workaround, link below: https://github.com/microsoft/MSBuildLocator/issues/86

ricardo-espinoza commented 4 years ago

Resolved by pull request #566 .