KirillOsenkov / RoslynQuoter

Roslyn tool that for a given C# program shows syntax tree API calls to construct its syntax tree
http://roslynquoter.azurewebsites.net
Apache License 2.0
922 stars 118 forks source link

The below code gives an exception #30

Closed ghost closed 7 years ago

ghost commented 7 years ago
public class DpVatCode
{       
            public List<VatRate> GetAll( string cnString )
    {
        List<VatRate> result = new List<VatRate>();
        return result;
    }
     }

System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxParser.AddError[TNode](TNode node, ErrorCode code, Object[] args) at Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.LanguageParser.ConsumeUnexpectedTokens[TNode](TNode node) at Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ParseStatement(String text, Int32 offset, ParseOptions options, Boolean consumeFullText) at QuoterService.Controllers.QuoterController.Get(String sourceText, NodeKind nodeKind, Boolean openCurlyOnNewLine, Boolean closeCurlyOnNewLine, Boolean preserveOriginalWhitespace, Boolean keepRedundantApiCalls, Boolean avoidUsingStatic)

I'm splitting method and classes to avoid waiting too much for the statements and obtaining an unreadable code, your Syntax generator is great by the way even if those who wrote the objects for the code generator are not very kind with those like me who need to create a custom class code generator. ;) thank you for building this or I would go back to codedom :P

KirillOsenkov commented 7 years ago

Hi @SabrinaCs this is a known bug in Roslyn: https://github.com/KirillOsenkov/RoslynQuoter/issues/24

It should be fixed after I update to the latest Roslyn binaries. For now the workaround is to use Parse as: "File" setting, it doesn't crash.

Thanks.

ghost commented 7 years ago

Thanks for the tip, this tool is really a great help seen that there is not so much around about how to use Roslyn, I still find it really complicated, even comparing it with the old Codedom that was nothing like simple too. It would be nice to have a book about it a little bit more detailed than the Roslyn Succintly Alessandro Del Sole wrote, it is an help to understanding some concepts, but not exactly what is needed to create automated code generators like I do for my repetitive classes in projects. Thanks anyway for creating this tool.