Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during code generation - NullReferenceException #3219

Open
thomasjoscht opened this issue Dec 15, 2020 · 1 comment
Open

Error during code generation - NullReferenceException #3219

thomasjoscht opened this issue Dec 15, 2020 · 1 comment

Comments

@thomasjoscht
Copy link

Hey,

I've a problem with my openapi.json file openapi.zip for a MicroStrategy REST API. During Code generation an error occurs.

System.InvalidOperationException: Error while rendering Liquid template CSharp/Client.Class:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.NullReferenceException: Object reference not set to an instance of an object.

Runtime: Net50
at NSwag.CodeGeneration.Models.OperationModelBase`2.get_UnwrappedResultType() in C:\projects\nswag\src\NSwag.CodeGeneration\Models\OperationModelBase.cs:line 120
at NSwag.CodeGeneration.CSharp.Models.CSharpOperationModel.get_SyncResultType() in C:\projects\nswag\src\NSwag.CodeGeneration.CSharp\Models\CSharpOperationModel.cs:line 127

Do you have any hint why this happens? Perhaps the file is invalid? Does NSwag have any verbose log oportunities for analyzing this problem? Thx a lot.

Regards
Thomas

@thomasjoscht thomasjoscht changed the title Error during code generation - InvalidOperationException () Error during code generation - NullReferenceException Dec 15, 2020
@thomasjoscht
Copy link
Author

Hey,

I've found two problems:

Wrong build type

The build action of file Client.Class.Annotations in NSwag.CodeGeneration.CSharp/Templates is wrong. It is set to nothing instead of "embedded". This must be fixed.

Missing schema handling

In class OperationModelBase.UnwrappedResultType no check for missing schema exists. In my case the openapi.json is a little bit invalid because of sometimes missing schema definitions. Perhaps this should be fixed for a default to string or void.

Regards
Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant