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

Do not call FindReferencesAsync for null symbol #2089

Merged
merged 5 commits into from
Feb 13, 2021
Merged

Conversation

filipw
Copy link
Member

@filipw filipw commented Feb 12, 2021

At the moment, on finding references, when the requested symbol is null, we still call Roslyn reference finder API which then results in an ugly unhandled exception.

System.InvalidOperationException: Unexpected null\r\n at Roslyn.Utilities.Contract.Fail(String message)\r\n at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.MapToAppropriateSymbol(ISymbol symbol)\r\n at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d__20.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 Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.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 Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d__8.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 Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d__8.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 Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d__8.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 Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.d__34.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 Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.d__37.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.Roslyn.CSharp.Services.Navigation.FindUsagesService.d__2.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Roslyn.CSharp\\Services\\Navigation\\FindUsagesService.cs:line 41

This happens automatically when the member is invalid and in VS Code shows up in a horrible way:

Bildschirmfoto 2021-02-11 um 09 26 24

This also happens when you click anywhere in the code on a non-symbol e.g. the "public" keyword and try to use "find references"

Fixes dotnet/vscode-csharp#4382
Fixes #2054

@filipw filipw merged commit 6948027 into master Feb 13, 2021
@filipw filipw deleted the feature/refs-ex branch February 13, 2021 00:05
@VincentDondain
Copy link

VincentDondain commented Mar 24, 2021

Hey @filipw, how do I know if this has been released? I'm using the C# extension v1.23.9 and I still see that issue.

@filipw
Copy link
Member Author

filipw commented Mar 24, 2021

it was not integrated into the C# extension yet

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

Successfully merging this pull request may close these issues.

[OmniSharp] Exception on /findusages call InvalidOperationException: Unexpected null
4 participants