NeVeSpl / NTypewriter

File/code generator using Scriban text templates populated with C# code metadata from Roslyn API.
https://nevespl.github.io/NTypewriter/
MIT License
126 stars 24 forks source link

script started crashing after upgrade #50

Closed gregveres closed 2 years ago

gregveres commented 2 years ago

I think this started crashing after the latest upgrade, but it might have been before that. My script used the same syntax as shown in AngularWebAPIService example. Specifically, I had the same line as line 11.

bodyParameterName = (method | Action.BodyParameter)?.Name ?? "null"

this syntax looks correct. If method | Action.BodyParameter is null, then the ?.Name should not get evaluated and it should return "null" as the result.

However, with this line, I now get an error while running the script:

(53,56) Object `(method|Action.BodyParameter)` is null. Cannot access member: (method|Action.BodyParameter)?.Name

I have worked around the problem by changing my script code to use a ternary operator:

bodyParameterName = (method | Action.BodyParameter) ? (method | Action.BodyParameter)?.Name ?? "null" : "null"

I can't tell which version this started in because VS auto updates my extensions and the only reason I noticed the problem is because I tried to render the template and it failed today after VS auto updated to 0.3.2.1. The original error was because my project still used NTypewriter.Editor.Config.0.1.10-alpha Once I upgraded my project to NTypewriter.Editor.Config.0.3.1, I started to get this error.

I know that last week I was happily generating new api service classes using the script, so I have to assume it started with the latest version.

gregveres commented 2 years ago

BTW, thanks for the auto compilation settings. I will be test driving them over the next little while!

NeVeSpl commented 2 years ago

It was caused by commit 588ec04. I have temporary roll it back in version 0.3.2.2. The longer version is too long, I will try to fix Scriban behaviour because the shorter version is 100% correct, and should also work with disabled EnableRelaxedMemberAccess.

NeVeSpl commented 2 years ago

Small update, the fix already made it into Scriban code and it is waiting for the next release.