-
Notifications
You must be signed in to change notification settings - Fork 54
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
Fatal Compilation Error: preprocessor directives, not placed on new line #725
Comments
Temporary workaround: Fixate the SDK to a working version and disable rollforward in a global.json. This works for me:
|
thanks for the suggestion. I tried that, and then forced a regeneration (after a VS restart) and the result still contained malformed C#. |
I was able to temporarily suppress the generation of the [ValueObject<uint>
#if VOGEN_IS_BROKEN
( parsableForStrings: ParsableForStrings.GenerateNothing,
tryFromGeneration: TryFromGeneration.Omit,
parsableForPrimitives: ParsableForPrimitives.GenerateNothing )
#endif
] |
I'm running into the same issue. I put the SDK version back to I tried @aabs suggestion, but that [ValueObject<string>(
tryFromGeneration: TryFromGeneration.Omit,
parsableForPrimitives: ParsableForPrimitives.GenerateNothing
)]
public readonly partial struct PirepId; It's generating: /// <summary>
/// </summary>
/// <returns>
/// True if the value passes any validation (after running any optional normalization).
/// </returns>
public static global::System.Boolean TryParse(
#if NETCOREAPP3_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
global::System.String? s, global::System.IFormatProvider? provider,
#if NETCOREAPP3_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MaybeNullWhen(false)]
#endif
out PirepId result) |
Damn, looks like only back to |
Adding |
…eMaybeNullWhenFalse. Fixes SteveDunn#725.
…eMaybeNullWhenFalse. Fixes SteveDunn#725.
Thanks for the report. I think the problem was, at some point, I wrapped the attribute with |
Fix #725: Introduce line breaks in GenerateNotNullWhenTrueAttribute and GenerateMaybeNullWhenFalse
I just love how I stumbled across this issue just today and an hour later it's fixed <3 THX YOU ALL! AWESOME!!! |
Yes, this is fixed in 6.0.0-beta.3. I've created a Discord thread in the Roslyn channel as something has changed (but admittedly, the source that Vogen generated was also wrong, in that it needed preprocessors on their lines) |
For reference, this is the Roslyn bug report: |
I will add that it has been, at least in conversations on the discord, the public recommendation that generated code should not be run through a formatter. This is because formatting is incredibly slow and source generators should generate code quickly. As such, it is suggested that generators generate good enough code and not use formatters at all. |
Not sure if you want a dependency on efcore but they're using a StringBuilder that supports indentation. |
Thanks @Khaos66 - I'll take a look |
Thank you. Yes, I was in two minds whether to format or not as I anticipated some performance overhead. I really need to get around to profiling Vogen as I'm sure there's areas that could be optimised. |
Describe the bug
Getting errors after updating to Microsoft Visual Studio Professional 2022 (64-bit) - Preview
Version 17.13.0 Preview 2.0.
The error messages produced indicate malformed code generation in Vogen:
The original code looks like this:
The generated code contains this:
Note the fragment
TryFrom( #if NETCOREAPP
which is invalid.Steps to reproduce
Update VS to latest preview (17.13.0 Preview 2.0).
Rebuild the code. Build will fail with the above issue.
I tried updating to the latest version of the Nuget pkg (5.0.6) and restarting VS, but the code generated still broke.
Expected behaviour
The
#if
should be on a new line. Then all should be fine.The text was updated successfully, but these errors were encountered: