dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.88k stars 676 forks source link

OmniSharp does not recognize classes, members, and props generated by CsWin32 #5080

Closed BinToss closed 2 weeks ago

BinToss commented 2 years ago

Issue Description

Although the root cause seemed to have been resolved in 2021 by the Roslyn and CsWin32 teams, OmniSharp still doesn't recognize CsWin32's generated code (which works perfectly in Visual Studio IDE).

Steps to Reproduce

dotnet new wpf --langVersion 9 --lang dotnet add package Microsoft.Windows.CsWin32 --prerelease New-Item NativeMethods.txt "DeviceIoControl" > NativeMethods.txt add using Windows.Win32 and using Microsoft.Win32 Call DeviceIoControl() from App.xaml.cs dotnet build *.csproj

Build will succeed despite OmniSharp's Error highlights.

Expected Behavior

Actual Behavior

The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?) - csharp(CS0246) Unsafe code may only appear if compiling with /unsafe - csharp(CS0227) The name 'PInvoke' does not exist in the current context - csharp(CS0103)

Logs

OmniSharp log

Starting OmniSharp server at 2/26/2022, 2:56:02 AM Target: d:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src\HXE.sln OmniSharp server started. Path: c:\Users\Noah\.vscode\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\OmniSharp.exe PID: 18000 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 6.2.9200.0 (x64) [info]: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK [info]: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 4 MSBuild instance(s) 1: Visual Studio Community 2022 17.1.32210.238 17.1.0 - "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin" 2: Visual Studio Community 2019 16.11.32106.194 16.11.2 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" 3: Visual Studio Community 2022 17.1.32203.90 17.1.0 - "C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin" 4: StandAlone 17.0.0 - "c:\Users\Noah\.vscode\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\.msbuild\Current\Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Visual Studio Community 2022 17.1.32210.238 17.1.0 - "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin" [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'd:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src'. [info]: OmniSharp.Cake.CakeProjectSystem Did not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem Detecting projects in 'd:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src\HXE.sln'. [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'd:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src\HXE.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'd:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src'. [info]: OmniSharp.Script.ScriptProjectSystem Did not find any CSX files [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'd:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src' on host 6880. [info]: OmniSharp.MSBuild.ProjectManager Loading project: d:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src\HXE.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'd:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src\HXE.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project 'd:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src\HXE.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: HXE [info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers Solution initialized -> queue all documents for code analysis. Initial document count: 54. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: d:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src\Common\FileSystemCompression.cs, Line: 36, Column: 33. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No symbol found. File: d:\Repos\HaloSPV3\SPV3.Loader\ext\hxe\src\Common\FileSystemCompression.cs, Line: 36, Column: 28. Received response for /v2/getcodeactions but could not find request. Received response for /v2/getcodeactions but could not find request. Received response for /v2/getcodeactions but could not find request. [warn]: OmniSharp.Stdio.Host ************ Request ************ { "Type": "request", "Seq": 295, "Command": "/v2/getcodeactions", "Arguments": { "FileName": "d:\\Repos\\HaloSPV3\\SPV3.Loader\\ext\\hxe\\src\\Common\\FileSystemCompression.cs", "Line": 36, "Column": 28 } } [fail]: OmniSharp.Stdio.Host ************ Response (1209.4932ms) ************ { "Request_seq": 295, "Command": "/v2/getcodeactions", "Running": true, "Success": false, "Message": "\"System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.\\r\\n at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)\\r\\n at System.Reflection.RuntimeAssembly.get_DefinedTypes()\\r\\n at System.Linq.Enumerable.d__17`2.MoveNext()\\r\\n at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\\r\\n at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\\r\\n at System.Linq.Enumerable.d__59`1.MoveNext()\\r\\n at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\\r\\n at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\\r\\n at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.LoadFrom(Project project) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 93\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.GetAllCodeFixesForProject(ProjectId projectId) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 57\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.GetSortedCodeFixProviders(Document document) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 156\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.d__13.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.d__12.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 123\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.d__9.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 80\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService.d__1.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\GetCodeActionsService.cs:line 32\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Endpoint.EndpointHandler`2.d__19.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Endpoint.EndpointHandler`2.d__20.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 230\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Endpoint.EndpointHandler`2.d__16.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 131\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Stdio.Host.d__14.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Stdio\\\\Host.cs:line 218\"", "Body": null, "Seq": 73, "Type": "response" }

C# log

Installing C# dependencies... Platform: win32, x86_64 Finished

Environment information

VSCode version: 1.64.2 C# Extension: 1.24.0

Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.200-preview.22055.15 Commit: a3c3a2bf3b Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.200-preview.22055.15\ Host (useful for support): Version: 6.0.1 Commit: 3a25a7f1cc .NET SDKs installed: 3.1.416 [C:\Program Files\dotnet\sdk] 5.0.403 [C:\Program Files\dotnet\sdk] 5.0.404 [C:\Program Files\dotnet\sdk] 5.0.405 [C:\Program Files\dotnet\sdk] 6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk] 6.0.101 [C:\Program Files\dotnet\sdk] 6.0.200-preview.22055.15 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |angelscript|renesackers|1.0.3| |auto-using|Fudge|0.7.15| |better-cpp-syntax|jeff-hykin|1.15.13| |cmake|twxs|0.0.17| |cmake-tools|ms-vscode|1.9.2| |code-spell-checker|streetsidesoftware|2.1.7| |code-stats-vscode|riussi|1.0.18| |codespaces|GitHub|1.5.4| |cpptools|ms-vscode|1.8.4| |cpptools-extension-pack|ms-vscode|1.1.0| |cpptools-themes|ms-vscode|1.0.0| |csharp|ms-dotnettools|1.24.0| |docomment|k--kato|0.1.30| |docs-article-templates|docsmsft|0.2.11| |docs-images|docsmsft|0.0.9| |docs-linting|docsmsft|0.0.9| |docs-metadata|docsmsft|1.0.7| |docs-preview|docsmsft|0.3.57| |docs-visual-areas|docsmsft|0.2.1| |docs-yaml|docsmsft|0.2.7| |dotnet-interactive-vscode|ms-dotnettools|1.0.3103010| |doxdocgen|cschlosser|1.4.0| |EditorConfig|EditorConfig|0.16.4| |even-better-toml|tamasfe|0.14.2| |file-header|bookworms|0.0.1| |file-icons|file-icons|1.0.29| |file-properties-viewer|brunnerh|1.0.0| |gc-excelviewer|GrapeCity|4.0.50| |github-markdown-preview|bierner|0.2.0| |gitlens|eamodio|11.7.0| |hexeditor|ms-vscode|1.9.5| |html-css-class-completion|Zignd|1.20.0| |java|redhat|1.3.0| |jupyter|ms-toolsai|2022.1.1301854968| |jupyter-keymap|ms-toolsai|1.0.0| |jupyter-renderers|ms-toolsai|1.0.6| |LinkCheckMD|blackmist|0.3.1| |live-server|ms-vscode|0.2.12| |LogFileHighlighter|emilast|2.15.0| |makefile-tools|ms-vscode|0.3.1| |markdown-checkbox|bierner|0.3.2| |markdown-emoji|bierner|0.2.1| |markdown-footnotes|bierner|0.0.7| |markdown-preview-github-styles|bierner|1.0.1| |markdown-yaml-preamble|bierner|0.1.0| |msbuild-project-tools|tintoy|0.4.3| |msbuild-tools|sterin|0.0.12| |npm-intellisense|christian-kohler|1.4.1| |nsis|idleberg|3.48.0| |nsis-plugins|idleberg|1.3.1| |nugetpackagemanagergui|aliasadidev|1.1.9| |powershell-preview|ms-vscode|2022.2.2| |prettyxml|PrateekMahendrakar|1.4.0| |python|ms-python|2022.0.1814523869| |qub-msbuild|qub|0.6.3| |rainbow-csv|mechatroner|2.0.0| |reload|natqe|0.0.6| |remote-containers|ms-vscode-remote|0.217.4| |remote-ssh|ms-vscode-remote|0.74.0| |remote-ssh-edit|ms-vscode-remote|0.74.0| |remote-wsl|ms-vscode-remote|0.64.2| |remotehub|GitHub|0.24.0| |reopenclosedtab|uyiosa-enabulele|1.1.0| |roslynator|josefpihrt-vscode|4.0.3| |ruby|rebornix|0.28.1| |sarif-viewer|MS-SarifVSCode|3.1.1| |SecurityIntelliSense|azsdktm|0.8.0| |shader|slevesque|1.1.5| |solutionextension|Tobias-Sekan|1.9.2| |test-adapter-converter|ms-vscode|0.1.5| |toml|be5invis|0.6.0| |vs-keybindings|ms-vscode|0.2.1| |vscode|unoplatform|0.2.5| |vscode-cdb|MicrosoftDebuggingPlatform|0.0.6| |vscode-codeql|GitHub|1.5.11| |vscode-conventional-commits|vivaxy|1.24.0| |vscode-detect-charset|yeluoqiuzhi|0.0.1| |vscode-devskim|MS-CST-E|0.6.8| |vscode-github-actions|cschleiden|0.22.0| |vscode-html-css|ecmel|1.11.0| |vscode-java-debug|vscjava|0.38.0| |vscode-java-dependency|vscjava|0.19.0| |vscode-java-pack|vscjava|0.21.0| |vscode-java-test|vscjava|0.34.0| |vscode-markdown-notebook|ms-vscode|0.0.26| |vscode-markdownlint|DavidAnson|0.46.0| |vscode-maven|vscjava|0.35.0| |vscode-npm-script|eg2|0.3.24| |vscode-pull-request-github|GitHub|0.36.2| |vscode-pylance|ms-python|2022.2.4| |vscode-ruby|wingrunr21|0.28.0| |vscode-solution-explorer|fernandoescolar|0.4.5| |vscode-test-explorer|hbenl|2.21.1| |vscode-typescript-next|ms-vscode|4.7.20220225| |vscode-xml|redhat|0.19.1| |vscode-xml-complete|rogalmic|0.3.0| |vscode-yaml|redhat|1.4.0| |vscodeintellicode|VisualStudioExptTeam|1.2.17| |xml|DotJoshJohnson|2.5.1|;
BinToss commented 2 years ago

https://github.com/microsoft/CsWin32/issues/7 This related issue applies to .NET SDK 5. I'm using .NET SDK 6 which has the suggested workaround applied by default.

nohwnd commented 2 years ago

Might be related to how design time build is done.

JoeRobich commented 2 weeks ago

Closing due to lack of activity.