This project is read-only.
1
Vote

CSharpSyntaxRewriter. VisitRegionDirectiveTrivia returning null throws

description

When overriding the VisitRegionDirectiveTrivia method of CSharpSyntaxRewriter class, returning null in order to remove the #region directive throws NullReferenceException.
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.SyntaxFactory.Trivia(StructuredTriviaSyntax node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitTrivia(SyntaxTrivia trivia)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement(SyntaxTrivia element)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList(SyntaxTriviaList list)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitToken(SyntaxToken token)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitUsingDirective(UsingDirectiveSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList`1 list)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitCompilationUnit(CompilationUnitSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)

comments