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

Endless warnings when generated code is compiled with nullable #136

Open
cho-regin opened this issue Sep 8, 2023 · 8 comments
Open

Endless warnings when generated code is compiled with nullable #136

cho-regin opened this issue Sep 8, 2023 · 8 comments

Comments

@cho-regin
Copy link

The code generated by the ModelCompiler needs to at least output #nullable disable or preferably generate code that compiles without warnings when nullable is enabled.

@opcfoundation-org
Copy link
Contributor

Can you provide the places where the #nullable disable needs to go?

@cho-regin
Copy link
Author

cho-regin commented Sep 8, 2023

at the top of the .Classes.cs file and the .DataTypes.cs file. The files are riddled with nullable violations

@opcfoundation-org
Copy link
Contributor

Not surprising since the code was written before that feature existed in the C# language. But it also means that making it nullable compliant would break existing code so it can never be more than option that has to be enabled during generation.

@opcfoundation-org
Copy link
Contributor

Looks like #nullable disable is not an option given all the different frameworks that the Core library has to build against:
Error CS8370 Feature 'nullable reference types' is not available in C# 7.3. Please use language version 8.0 or greater.

See OPCFoundation/UA-.NETStandard#2300

@cho-regin
Copy link
Author

cho-regin commented Sep 8, 2023

crazy that there is no preprocessor switch that could help here... but a commandline switch during generation would be perfectly fine!

@opcfoundation-org
Copy link
Contributor

The language version is explicitly set to 7.3 in the Core library.
If you know a way to create a constant like this:

#if CSHARP_8_OR_NEWER
#nullable disable
#endif

Then it will be possible to update the generated code.
I tried to find a way to do it but none of them worked and I have no more time right now.

@cho-regin
Copy link
Author

I also tried to find a solution like that but I could not find a pretty one. The best solution would be to add a nullable switch to the executable but then it would a bit much to add that switch just to print those three lines... Ideally it would be nice to have a switch to properly generate nullable enabled code but I realize that is not so simple...

@opcfoundation-org
Copy link
Contributor

Marked as nice-to-have enhancement but switching to nullable is not trival. It requires a rethink of almost every line of code.

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

No branches or pull requests

2 participants