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

Generated C# DateFormatConverter for System.Text.Json does not use full name for JsonException #1515

Closed
pvaillant opened this issue Apr 25, 2022 · 2 comments

Comments

@pvaillant
Copy link

If you generate a C# client with a model that has a property with type: string and format: date, and are using JsonLibrary SystemTextJson then the generated client fails to compile with the following error:

error CS0246: The type or namespace name 'JsonException' could not be found

The issue is here; the generated DateFormatConverter does not specify the full name for JsonException.
https://github.com/RicoSuter/NJsonSchema/blob/master/src/NJsonSchema.CodeGeneration.CSharp/Templates/DateFormatConverter.liquid#L10

throw new JsonException("Unexpected JsonTokenType.Null");

This code (PR #1490) comes from issue #1486. In the issue, the proposed code has the correct full name:

throw new System.Text.Json.JsonException("Unexpected JsonTokenType.Null");

So it seems to just have been missed in the PR.

I'm happy to create a PR for the fix if that's helpful.

@pvaillant
Copy link
Author

And in case anyone else is having the same issue and it using .Net 6, you can work around it with global using System.Text.Json;

@AroglDarthu
Copy link
Contributor

Good catch! Seems to have been fixed now by #1505

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

3 participants