Fix NRE in WTG1010 when analyzing conditional invoke expressions#238
Open
Copilot wants to merge 2 commits into
Open
Fix NRE in WTG1010 when analyzing conditional invoke expressions#238Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
When the invocation's expression is a MemberBindingExpression (e.g., obj?.TryGetValue(...)), rewrite the speculative expression as a regular member access to provide the necessary binding context for Roslyn's speculative symbol resolution. Fixes the NullReferenceException that occurred because the invocation node alone doesn't contain the conditional access target information needed by the binder. Agent-Logs-Url: https://github.com/WiseTechGlobal/WTG.Analyzers/sessions/62f30448-c8d6-4608-8142-a1c3fece533b Co-authored-by: brian-reichle <18721383+brian-reichle@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix NRE in WTG1010 analyzer for conditional invoke
Fix NRE in WTG1010 when analyzing conditional invoke expressions
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
VarAnalyzer.AnalyzeInvokethrows aNullReferenceExceptionwhen processing conditional access invocations (e.g.,obj?.TryGetValue("key", out object val)). The speculative binding of the rewrittenInvocationExpressionSyntaxfails because aMemberBindingExpressionnode lacks the conditional access receiver context that Roslyn's binder requires.Changes
VarAnalyzer.cs— When the invocation expression is aMemberBindingExpressionSyntaxinside aConditionalAccessExpressionSyntax, rewrite the speculative expression as a regularMemberAccessExpressionusing the conditional access target so the binder can resolve the receiver.VarFixAllProvider.cs— Same fix applied to theReplaceTypesmethod which has the identical speculative binding pattern.Lookup?.TryGetValue("key", out string value)) to theOutsample.