Skip to content

roslynator tool fails on removing unused code when project has code generated files #1549

@prezaei

Description

@prezaei

Product and Version Used:
roslynator find-symbol --symbol-kind type --unused --remove
Latest version of the tool (4.1.7)

Steps to Reproduce:
We use .NET Source Generator for IOptions validation. These are not physical files and should be ignored by Roslynator.

https://learn.microsoft.com/en-us/dotnet/core/extensions/options-validation-generator

Actual Behavior:

    class  __OptionValidationStaticInstances.__Validators
System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Roslynator.CommandLine.FindSymbolCommand.RemoveSymbolsAsync(ImmutableArray`1 symbols, Project project, CancellationToken cancellationToken) in /_/src/CommandLine/Commands/FindSymbolCommand.cs:line 181
   at Roslynator.CommandLine.FindSymbolCommand.ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken) in /_/src/CommandLine/Commands/FindSymbolCommand.cs:line 99
   at Roslynator.CommandLine.MSBuildWorkspaceCommand`1.ExecuteAsync(String path, MSBuildWorkspace workspace, CancellationToken cancellationToken) in /_/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs:line 164
   at Roslynator.CommandLine.MSBuildWorkspaceCommand`1.ExecuteAsync(IEnumerable`1 paths, String msbuildPath, IEnumerable`1 properties) in /_/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs:line 89
   at Roslynator.CommandLine.Program.FindSymbolAsync(FindSymbolCommandLineOptions options) in /_/src/CommandLine/Program.cs:line 392
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Roslynator.CommandLine.Program.<>c.<Main>b__0_3(MSBuildCommandLineOptions options) in /_/src/CommandLine/Program.cs:line 195
   at CommandLine.ParserResultExtensions.MapResult[T1,T2,TResult](ParserResult`1 result, Func`2 parsedFunc1, Func`2 parsedFunc2, Func`2 notParsedFunc)
   at Roslynator.CommandLine.Program.Main(String[] args) in /_/src/CommandLine/Program.cs:line 169

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions