OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.78k stars 419 forks source link

Error when trying to open a .NET 7 project in NixOS #2426

Closed GGG-KILLER closed 2 years ago

GGG-KILLER commented 2 years ago

So, I've been testing out .NET 7 in NixOS and the project building, restoring and running works, however when opening a project in VSCode using OmniSharp results in an error:

Exception ``` Microsoft.Build.Exceptions.InvalidProjectFileException: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. File name: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio)"" /home/ggg/test/test.csproj at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1](IElementLocation elementLocation, String resourceName, T1 arg0) at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError) at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult) at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator`4.Evaluate() at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive) at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, String toolsVersion) at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore(String filePath, IReadOnlyDictionary`2 projectConfigurationsInSolution, IList`1 loggers) in /build/source/src/OmniSharp.MSBuild/ProjectLoader.cs:line 162 at OmniSharp.MSBuild.ProjectLoader.BuildProject(String filePath, IReadOnlyDictionary`2 configurationsInSolution) in /build/source/src/OmniSharp.MSBuild/ProjectLoader.cs:line 84 at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load(String filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader, Guid sessionId, DotNetInfo dotNetInfo) in /build/source/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs:line 117 at OmniSharp.MSBuild.ProjectManager.<>c__DisplayClass32_0.b__0() in /build/source/src/OmniSharp.MSBuild/ProjectManager.cs:line 305 at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject(String projectFilePath, Func`1 loader) in /build/source/src/OmniSharp.MSBuild/ProjectManager.cs:line 316 /home/ggg/test/test.csproj(0,0) Microsoft.Build.Exceptions.InvalidProjectFileException: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. File name: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio)"" /home/ggg/test/test.csproj at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1](IElementLocation elementLocation, String resourceName, T1 arg0) at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError) at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult) at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator`4.Evaluate() at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive) at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, String toolsVersion) at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore(String filePath, IReadOnlyDictionary`2 projectConfigurationsInSolution, IList`1 loggers) in /build/source/src/OmniSharp.MSBuild/ProjectLoader.cs:line 162 at OmniSharp.MSBuild.ProjectLoader.BuildProject(String filePath, IReadOnlyDictionary`2 configurationsInSolution) in /build/source/src/OmniSharp.MSBuild/ProjectLoader.cs:line 84 at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load(String filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader, Guid sessionId, DotNetInfo dotNetInfo) in /build/source/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs:line 117 at OmniSharp.MSBuild.ProjectManager.<>c__DisplayClass32_0.b__0() in /build/source/src/OmniSharp.MSBuild/ProjectManager.cs:line 305 at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject(String projectFilePath, Func`1 loader) in /build/source/src/OmniSharp.MSBuild/ProjectManager.cs:line 316 ```

Reproduction steps

I've made a repo with a full repro along with steps and the nixos config needed to build the machine or VM: https://github.com/GGG-KILLER/omnisharp-repro-config

Extra Info

System.Runtime.dll location

$ find -L /nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/ -name "System.Runtime.dll"
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/packs/Microsoft.NETCore.App.Ref/7.0.0-preview.6.22324.4/ref/net7.0/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/packs/Microsoft.NETCore.App.Ref/5.0.0/ref/net5.0/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/packs/Microsoft.NETCore.App.Ref/3.1.0/ref/netcoreapp3.1/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/packs/Microsoft.NETCore.App.Ref/6.0.6/ref/net6.0/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/packs/NETStandard.Library.Ref/2.1.0/ref/netstandard2.1/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/shared/Microsoft.NETCore.App/3.1.26/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/shared/Microsoft.NETCore.App/6.0.6/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/shared/Microsoft.NETCore.App/5.0.12/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/shared/Microsoft.NETCore.App/7.0.0-preview.6.22324.4/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/sdk/7.0.100-preview.6.22352.1/Microsoft/Microsoft.NET.Build.Extensions/net461/lib/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/sdk/5.0.403/Microsoft/Microsoft.NET.Build.Extensions/net461/lib/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/sdk/6.0.301/Microsoft/Microsoft.NET.Build.Extensions/net461/lib/System.Runtime.dll
/nix/store/gszxg52w60s671xpklyjv6ap4593a8j5-dotnet-core-combined/sdk/3.1.420/Microsoft/Microsoft.NET.Build.Extensions/net461/lib/System.Runtime.dll

If any more input is required feel free to mention me and I'll provide it to the best of my abilities.

GGG-KILLER commented 2 years ago

Ok, seems like this might be an issue with the way we're building OmniSharp in NixOS, I'll investigate further and if it turns out to be an OmniSharp issue I'll reopen.

SkyLeite commented 1 year ago

Hey, did you end up finding a solution for this?

GGG-KILLER commented 1 year ago

I fixed the way we were building OmniSharp in NixOS, the issue was with the way it was building. Don't know if it has returned because now I'm using the new C# VSCode extension which uses the Roslyn Language Server.