Analysis fails with null reference error
Closed this issue · 3 comments
Analysis keeps crashing with the following warnings.
I have 397 warnings only for this class. This is not even my code, this class comes directly from ASP .NET Core, which is written by Microsoft:
Severity Code Description Project File Line Suppression State
Warning AD0001 Analyzer 'Codartis.NsDepCop.VisualStudioIntegration.NsDepCopDiagnosticAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
Exception occurred with following context:
Compilation: Project.UI.Web
SyntaxTree: C:\Code\Solution\Project.UI.Web\Areas\Identity\RevalidatingIdentityAuthenticationStateProvider.cs
SyntaxNode: AspNetCore [IdentifierNameSyntax]@[118..128) (4,16)-(4,26)
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.Shell.ThreadHelper.get_JoinableTaskContext()
at Codartis.NsDepCop.VisualStudioIntegration.NsDepCopDiagnosticAnalyzerBase.AnalyzeSyntaxNodeAndLogException(SyntaxNodeAnalysisContext context)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__58`1.<ExecuteSyntaxNodeAction>b__58_0(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
Suppress the following diagnostics to disable this analyzer: NSDEPCOP01, NSDEPCOP05 Fdw.UI.Web 1 Active
---
So there are two problems:
- RevalidatingIdentityAuthenticationStateProvider gives lots of NsDepCop warnings.
- Analyzer crashes on this file.
For problem 1:
- Even if this code comes from a project template, as long as it's part if the project, it gets analyzed by default.
- You can do one of the following:
- If you want to exclude this whole project from the analysis then either remove its config.nsdepcop file or set it to disabled:
<NsDepCopConfig IsEnabled="false" />
- If you want to exclude some files then use the ExcludedFiles attribute, eg:
<NsDepCopConfig IsEnabled="true" ExcludedFiles="**\Identity\*.cs" />
- If you want to exclude this whole project from the analysis then either remove its config.nsdepcop file or set it to disabled:
For problem 2:
- I need to reproduce the problem so I can debug it.
- Which version of Visual Studio do you use?
- Which version of NsDepCop do you use?
- Can you post a minimal project that reproduces the crash?
I use VS 2019 and nsdepcop version: 1.10.1.
I just realized this issue could be because I am running a Blazor app, which targets .NET Core 3.1.
I didn't know NsDepCop doesn't support .net core.
The class that is the cause of the error comes as part of the default template when you start a new Blazor (server-side) app (auth type: Individual User Accounts) project from VS.
It's unfortunate that nsdepcop doesn't work with .net core, I was really looking forward to it.
There's a new version (v2.0) that supports .net core, please give it a try. You can find the RC1 version on NuGet.
Please feel free to reopen if it does not work for you.