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

OmniSharp unable to load project with Razor? #4446

Closed
ThomasAunvik opened this issue Mar 18, 2021 · 10 comments
Closed

OmniSharp unable to load project with Razor? #4446

ThomasAunvik opened this issue Mar 18, 2021 · 10 comments

Comments

@ThomasAunvik
Copy link

Environment data

dotnet --info output:

.NET SDK (reflecting any global.json):
 Version:   5.0.104
 Commit:    ca6b6acadb

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.104/

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

.NET SDKs installed:
  3.1.112 [/usr/share/dotnet/sdk]
  5.0.104 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

VS Code version: 1.54.3
C# Extension version: 1.23.9

OmniSharp log

https://gist.github.com/ThomasAunvik/e4bb57c12445136458908ce370445096

Steps to reproduce

I am not sure, but my it seems like my project is using Razor library from netstandard2.0 which fails to load the project that is running on core 3.1.

Expected behavior

To omnisharp to load the project correctly.

Actual behavior

Intellisense and other stuff like autocomplete stops working at all, and failes to load the main project.

[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/home/thaun/Documents/Projects/orkel-pi/ProductionInsight/Api/Api.csproj'.
/home/thaun/Documents/Projects/orkel-pi/ProductionInsight/Api/Api.csproj
/usr/share/dotnet/sdk/5.0.104/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.ScopedCss.targets(118,3): Error: The "Microsoft.AspNetCore.Razor.Tasks.DiscoverDefaultScopedCssItems" task could not be loaded from the assembly /usr/share/dotnet/sdk/5.0.104/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tasks/net46/Microsoft.NET.Sdk.Razor.Tasks.dll. Invalid Image Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: /home/thaun/Documents/Projects/orkel-pi/ProductionInsight/Api/Api.csproj```
@ThomasAunvik
Copy link
Author

Seems to be a Linux issue? Tried on Windows, and the project loaded fine, i should test this on an another linux system to see if i can reproduce the problem.

@nohwnd
Copy link
Member

nohwnd commented Apr 22, 2021

This looks like a problem in omnisharp-roslyn where incorrect Symbol is passed and ultimately fails in

  "Message": "\"System.InvalidOperationException: Unexpected null
  at Roslyn.Utilities.Contract.Fail (System.String message) [0x00000] in <1b72cf009970430282a46c2931a92a23>:0 
  at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.MapToAppropriateSymbol (Microsoft.CodeAnalysis.ISymbol symbol) [0x0003a] in <1b72cf009970430282a46c2931a92a23>:0 
...
at OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService.Handle (OmniSharp.Models.FindUsages.FindUsagesRequest request)

@JoeRobich
Copy link
Member

@ThomasAunvik It looks like this issue fixed in the version of OmniSharp (OmniSharp/omnisharp-roslyn#2054) that ships with the latest version of the C# extension. Are you still seeing this issue with the latest version?

@ThomasAunvik
Copy link
Author

ThomasAunvik commented Apr 29, 2021

Unfortunately yes, i am now at v1.23.11, and i have still the same issue.

@ThomasAunvik
Copy link
Author

ThomasAunvik commented Apr 29, 2021

I have created a test project with the similar functionality that i have in my own project, and can reproduce the project error.
Though it seems like it is something with the cshtml file that messes things up.

Here is the project: https://github.com/ThomasAunvik/RazorFailTest

image

When closing VSCode and then reloading the project, then i get the same error as the one in the original issue.

Though, it looks like the exception message is different now.

{
  "Request_seq": 169,
  "Command": "/v2/getcodeactions",
  "Running": true,
  "Success": false,
  "Message": "\"System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.\\nParameter name: index\\n  at Microsoft.CodeAnalysis.Text.SourceText+LineInfo.get_Item (System.Int32 index) [0x0000f] in <c001f5fa2dca450eb2e34735b8e99670>:0 \\n  at OmniSharp.Extensions.TextExtensions.GetPositionFromLineAndOffset (Microsoft.CodeAnalysis.Text.SourceText text, System.Int32 lineNumber, System.Int32 offset) [0x00006] in <270d63e46e6a4cfa971775e2bef24d75>:0 \\n  at OmniSharp.Extensions.TextExtensions.GetPositionFromPoint (Microsoft.CodeAnalysis.Text.SourceText text, OmniSharp.Models.V2.Point point) [0x0000d] in <270d63e46e6a4cfa971775e2bef24d75>:0 \\n  at OmniSharp.Extensions.TextExtensions.GetSpanFromRange (Microsoft.CodeAnalysis.Text.SourceText text, OmniSharp.Models.V2.Range range) [0x00007] in <270d63e46e6a4cfa971775e2bef24d75>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2[TRequest,TResponse].GetTextSpan (OmniSharp.Models.V2.CodeActions.ICodeActionRequest request, Microsoft.CodeAnalysis.Text.SourceText sourceText) [0x00015] in <ec1d3fb947a64fabb32b21e799311231>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2[TRequest,TResponse].GetAvailableCodeActions (OmniSharp.Models.V2.CodeActions.ICodeActionRequest request) [0x00128] in <ec1d3fb947a64fabb32b21e799311231>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService.Handle (OmniSharp.Models.V2.CodeActions.GetCodeActionsRequest request) [0x0006b] in <ec1d3fb947a64fabb32b21e799311231>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].GetFirstNotEmptyResponseFromHandlers (OmniSharp.Endpoint.Exports.ExportHandler`2[TRequest,TResponse][] handlers, TRequest request) [0x00099] in <0b0ae29b27aa47f6bc8003a40e46f189>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x00163] in <0b0ae29b27aa47f6bc8003a40e46f189>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <0b0ae29b27aa47f6bc8003a40e46f189>:0 \\n  at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger logger) [0x000e8] in <63c6b60bd8ce436698a3d2d17235a8d2>:0 \"",
  "Body": null,
  "Seq": 7593,
  "Type": "response"
}

@ThomasAunvik
Copy link
Author

ThomasAunvik commented Apr 30, 2021

Ok, so i haven't been able to reproduce the issue on an ubuntu vm for some reason, but i did manage to reproduce it in an Arch Linux vm.

Here is the virtual machine: Download VM
User and root password: password.

And then open Visual Studio Code at /home/thaun/Documents/Projects/RazorFaiLTest, though by opening visual studio code should already open the project since it was open from before.

Though, there might be this other related issue i am having now since the RID of this dotnet is incorrectly set to arch-x64 instead of linux-x64 for some reason, which is also reproduced in this vm, related forum post: https://bbs.archlinux.org/viewtopic.php?id=265923

@JoeRobich
Copy link
Member

@ThomasAunvik Thanks for all the great resources that you've provided.

This issue is a packaging issue with Arch's dotnet-sdk package where the net46 Razor build tasks are missing from the Razor SDK. This file /usr/share/dotnet/sdk/5.0.104/Sdks/Microsoft.NET.Sdk.Razor/tasks/net46/Microsoft.NET.Sdk.Razor.Tasks.dll is missing from the package file listing https://archlinux.pkgs.org/rolling/archlinux-community-x86_64/dotnet-sdk-5.0.5.sdk202-1-x86_64.pkg.tar.zst.html.

Your project builds fine using dotnet build because it looks for the net5 build tasks which are available. Because the C# extension relies on Mono to support .NET Full Framework projects, we look for the Full Framework net46 build tasks which are missing.

This comment provides a work around #4360 (comment) or you can try installing the dotnet-sdk-bin package which appears to have the necessary file https://archlinux.pkgs.org/rolling/chaotic-aur-x86_64/dotnet-sdk-bin-5.0.3.sdk200-1-x86_64.pkg.tar.zst.html.

@NTaylorMullen just a fyi

@NTaylorMullen
Copy link
Contributor

@pranavkm @captainsafia is the SDK bit intentional or known?

@JoeRobich
Copy link
Member

Wonder if this is a result of the Arch package being generated from source-build - https://github.com/archlinux/svntogit-community/blob/75fbd7b1a57ef88c5696a2e57fc8dd7ca910f21e/trunk/PKGBUILD#L91-L104. I don't imagine that it would build the full framework assemblies.

@ThomasAunvik
Copy link
Author

It would seem downloading the -bin version fixed the problem 👍
Closing this issue since #4360 already exists.

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

No branches or pull requests

4 participants