null check a token's parent to prevent a NullReferenceException - #1234
Conversation
This enables us to remove a try/catch block that was specifically added to find this NRE.
There was a problem hiding this comment.
The true diff is adding the conditional access on this line token.Parent?.GetAncestorsOrThis and on one line below.
|
👍 |
2 similar comments
|
👍 |
|
👍 |
|
Okay, now we know that we are getting asked to trigger signature help on a token with a null parent. Where did that token come from? |
|
My WinDbg-fu is weak, but from what I can tell from the stack objects here's what I was able to re-create:
The only way I could see this happening was if the trigger character was the first non-trivia token in the file, but I could never find a manual repro. |
|
I wonder if this happens when the token is in skipped trivia because of some previous error. |
|
Digging deeper into this with @Pilchie's help we determined that the issue was not a CompilationUnitSyntax that didn't have a parent, but rather |
|
test this please |
null check a token's parent to prevent a NullReferenceException
|
👍 |
|
I have another repro of what looks like the same issue. Can you please check? Place the cursor at the end of that line, open signature help, then press Ctrl+Home. |
|
@SLaks yes, this is the same issue. Thanks for finding a manual repro for this! I couldn't find one earlier so I was fixing this blindly. This repro looks like a different entry point than I originally encountered, but it's interesting nonetheless in that it causes the same null parent. In this case, signature help is open, Ctrl+Home is typed which moves the cursor to the top of the file, then tl;dr - with these changes, |
Update package versions (part 2) * SDK * System.Format.Asn1 * Nuget.* * Now that nuget packages are updated, can converge some #if related logic
This enables us to remove a try/catch block that was specifically added to find this NRE.
Fixes #1187.