OmniSharp / omnisharp-roslyn

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

Linux v1.37.1 fail on basic project #1947

Closed snowgoon88 closed 4 years ago

snowgoon88 commented 4 years ago

I wanted to try Emacs+lsp-mode on Ubuntu 20.04 but failed. I have the impression that omnisharp-roselyn is not able to deal even with a simple C# on my architecture.

I created a simple project in dir TestCSharp with dotnet new console. Then run omnisharp on this directory with run -l debug and many errors with missing files and, at the end, lsp-mode detecting a lot of undue errors.

 Program.cs     1   1 info     CS8019 Unnecessary using directive. (lsp)
 Program.cs     1   7 error    CS0246 **The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)** (lsp)
 Program.cs     5  11 error    CS0518 Predefined type 'System.Object' is not defined or imported (lsp)
 Program.cs     5  11 error    CS1729 'object' does not contain a constructor that takes 0 arguments (lsp)
 Program.cs     7  16 error    CS0518 Predefined type 'System.Void' is not defined or imported (lsp)
 Program.cs     7  26 error    CS0518 Predefined type 'System.String' is not defined or imported (lsp)
 Program.cs     9  13 error    CS0518 Predefined type 'System.Object' is not defined or imported (lsp)
 Program.cs     9  13 error    CS0103 **The name 'Console' does not exist in the current context** (lsp)
 Program.cs     9  31 error    CS0518 Predefined type 'System.String' is not defined or imported (lsp)

console.log the result of running omnisharp-roselyn with run -l debug in the project directory https://gist.github.com/snowgoon88/440a944f20b50b52f0e89c17eba9930f#file-console-log

where

Program.cs the simple c# code https://gist.github.com/snowgoon88/440a944f20b50b52f0e89c17eba9930f#file-program-cs

TestCSharp.csproj no surprise https://gist.github.com/snowgoon88/440a944f20b50b52f0e89c17eba9930f#file-testcsharp-csproj

flycheck.errors the errors displayed by flycheck on emacs. https://gist.github.com/snowgoon88/440a944f20b50b52f0e89c17eba9930f#file-flycheck-errors

(it is even worse on a project on Unity3D where the .csproj cannot be added)

filipw commented 4 years ago

@david-driscoll any idea?

SP :: csharp:440749 initialized successfully
LSP :: Error from the Language Server: Internal Error - System.NullReferenceException: Object reference not set to an instance of an object
  at OmniSharp.LanguageServerProtocol.Handlers.OmniSharpDocumentSymbolHandler.Handle (OmniSharp.Extensions.LanguageServer.Protocol.Models.DocumentSymbolParams request, System.Threading.CancellationToken token) [0x00096] in <57f6177d3f2b4286a7d315a96dc1d7b3>:0 
  at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x0006d] in <1238dd34c3f54a5080acfb1001dda78e>:0 
  at MediatR.Pipeline.RequestPreProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x0013e] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestPostProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x0007e] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestExceptionProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x00084] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestExceptionProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x00276] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x00084] in <856ae299ee314304bc3affd17d8d5868>:0 
  at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, MediatR.RequestHandlerDelegate`1[TResponse] next) [0x001e7] in <856ae299ee314304bc3affd17d8d5868>:0 
  at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1[TDescriptor].<RouteRequest>g__InnerRoute|5_0 (Microsoft.Extensions.DependencyInjection.IServiceScopeFactory serviceScopeFactory, OmniSharp.Extensions.JsonRpc.Server.Request request, TDescriptor descriptor, System.Object params, System.Threading.CancellationToken token, Microsoft.Extensions.Logging.ILogger logger) [0x000f2] in <fba9e575570149efaee3484292339424>:0 
  at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1[TDescriptor].RouteRequest (OmniSharp.Extensions.JsonRpc.IRequestDescriptor`1[TDescriptor] descriptors, OmniSharp.Extensions.JsonRpc.Server.Request request, System.Threading.CancellationToken token) [0x005f3] in <fba9e575570149efaee3484292339424>:0 
  at OmniSharp.Extensions.JsonRpc.InputHandler+<>c__DisplayClass38_0.<RouteRequest>b__5 (System.Threading.CancellationToken ct) [0x000e8] in <fba9e575570149efaee3484292339424>:0  (Internal Error
snowgoon88 commented 4 years ago

Sorry; my fault : I did not restart my session after installing dotnet ! I usually do not need to do that on Linux :o) So, after a restart, everything work well on the basic "console" project using ./Netcore 3.1.

But, as in #1948, my real problem is with Unity Assemblies. It seems that "my" Unity targets ./Net 4.7.1 and that omnisharp is not able to deal with it. Should I add this to #1948 ? Should I add more info (like the .csproj file ?)

Extract from run -v

{"Event":"log","Body":{"LogLevel":"ERROR","Name":"OmniSharp.MSBuild.ProjectLoader","Message":"The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks"},"Seq":86,"Type":"event"}
{"Event":"log","Body":{"LogLevel":"WARNING","Name":"OmniSharp.MSBuild.ProjectManager","Message":"Failed to load project file '/home/alain/Projets/Unity/ImPacman/Assembly-CSharp.csproj'."},"Seq":87,"Type":"event"}

{"Event":"MsBuildProjectDiagnostics","Body":{"FileName":"/home/alain/Projets/Unity/ImPacman/Assembly-CSharp.csproj","Warnings":[],"Errors":[{"LogLevel":"Error","FileName":"/home/alain/.emacs.d/.cache/lsp/omnisharp-roslyn/v1.37.1/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets","Text":"The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks","StartLine":1178,"StartColumn":5,"EndLine":0,"EndColumn":0}]},"Seq":88,"Type":"event"}
{"Event":"log","Body":{"LogLevel":"ERROR","Name":"OmniSharp.MSBuild.ProjectManager","Message":"Attempted to update project that is not loaded: /home/alain/Projets/Unity/ImPacman/Assembly-CSharp.csproj"},"Seq":89,"Type":"event"}

It seems strange to me because omnisharp comes with its own mono (and thus SDK I think), supposed to deal with .NET version 4.7.2

filipw commented 4 years ago

"The reference assemblies for .NETFramework,Version=v4.7.1 were not found."

This means you don't have global Mono available. OmniSharp ships its own minimal Mono, but that only contains trimmed types that are needed for OmniSharp to run, not reference assemblies for all versions of .NET.

The solution is to install global mono e.g. https://www.mono-project.com/download/stable/#download-lin

snowgoon88 commented 4 years ago

I have global mono available (version 6.8.0.105) but omnisharp-roselyn is not able to use it... I modified the run script to make it work. See https://github.com/emacs-lsp/lsp-mode/issues/2188#issuecomment-694945601 and another solution is maybe (not tested yet) : https://github.com/OmniSharp/omnisharp-roslyn/issues/1948#issuecomment-694869256

Thanks everyone :o)

filipw commented 4 years ago

thanks. then I will close this issue as it's not an OmniSharp problem. It has the capability of discovering global Mono (e.g. VS Code uses it for Unity support) but it's the responsibility of the client that implements OmniSharp