AD0001: NullReferenceException #79059
-
I'm trying to create a code analyzer for a project. I've been following various guides I've found online but am now completely stuck. Whatever I do I get an |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
What OS/IDE are you using for development? For Windows+Visual Studio, the default analyzer template should include a project suffixed ".Vsix". If you "Debug>start new instance" on that, it should launch+attach debugger to a second instance of VS which has your analyzer loaded as an extension. Then, as long as you have the debugger set up to break on the particular exception type (which it should by default), you can just navigate to some code which was crashing your analyzer, and have the debugger break, and you'll be able to inspect what is going on. Ideally, if you have some suspicion that a particular coding pattern is crashing the analyzer, you would create a unit test for the scenario and repro/fix that way. That would probably be somewhat easier to do. See Analyzers.Test for samples of that. |
Beta Was this translation helpful? Give feedback.
You may be missing a VS optional component which is recommended in this scenario: https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix . I recommend you at least take a look at the template and extract out bits that look useful, as it is intended to address these basic quality of life issues for analyzer development.
Glancing at your code the following looks broken to me:
https://github.com/csuzw/curly-doodle/blob/d892f633b85cd07e1b3b09bd0460742acd324b3f/Infuriating.CodeAnalysis/MyRule.cs#L21
Unfortunately ImmutableArray due to being a struct has some weird ergonomics. Your code is creating a
new ImmutableArray<DiagnosticDescriptor>()
,…