question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GenAPI produces invalid source code for record properties

See original GitHub issue

Repro steps in SBRP

  1. generate.sh --package "Microsoft.Build,16.10.0" --exclude-package-dependencies
  2. ./.dotnet/dotnet build src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj

GenAPI produces the following code:

        public virtual GraphBuildOptions <Clone>$() { throw null; }

Errors

/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net472/Microsoft.Build.cs(2559,49): error CS1519: Invalid token '$' in class, record, struct, or interface member declaration [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net472]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net472/Microsoft.Build.cs(2559,49): error CS1056: Unexpected character '$' [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net472]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net472/Microsoft.Build.cs(2559,51): error CS8124: Tuple must contain at least two elements. [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net472]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net472/Microsoft.Build.cs(2559,53): error CS1519: Invalid token '{' in class, record, struct, or interface member declaration [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net472]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net472/Microsoft.Build.cs(2730,1): error CS1022: Type or namespace definition, or end-of-file expected [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net472]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net5.0/Microsoft.Build.cs(2555,49): error CS1519: Invalid token '$' in class, record, struct, or interface member declaration [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net5.0]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net5.0/Microsoft.Build.cs(2555,49): error CS1056: Unexpected character '$' [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net5.0]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net5.0/Microsoft.Build.cs(2555,51): error CS8124: Tuple must contain at least two elements. [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net5.0]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net5.0/Microsoft.Build.cs(2555,53): error CS1519: Invalid token '{' in class, record, struct, or interface member declaration [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net5.0]
/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/lib/net5.0/Microsoft.Build.cs(2726,1): error CS1022: Type or namespace definition, or end-of-file expected [/home/vihofer/git/source-build-reference-packages/src/referencePackages/src/microsoft.build/16.10.0/Microsoft.Build.16.10.0.csproj::TargetFramework=net5.0]

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ViktorHofercommented, Mar 24, 2023
1reaction
KalleOlaviNiemitalocommented, Mar 7, 2023

It seems the following members would also need to be generated

partial class GraphBuildOptions
{
    public override string ToString() { throw null; }
    protected virtual bool PrintMembers(System.Text.StringBuilder builder) { throw null; }
    public static bool operator !=(GraphBuildOptions? left, GraphBuildOptions? right) { throw null; }
    public static bool operator ==(GraphBuildOptions? left, GraphBuildOptions? right) { throw null; }
    public override bool Equals(object? obj) { throw null; }
    public bool Equals(GraphBuildOptions? other) { throw null; }
    public override int GetHashCode() { throw null; }
    protected GraphBuildOptions(GraphBuildOptions original) {}
    public GraphBuildOptions() {}
}

but the <Clone>$() method is still a problem. If you consume the reference assembly with this kind of code

static class C
{
    static void M()
    {
        _ = new GraphBuildOptions() with { Build = true };
    }
}

then it tries to call the <Clone>$() method, and fails to compile if that does not exist.

So, I think GenAPI needs to generate the C# record syntax.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft.UI.Xaml.Markup.Compiler generates invalid code ...
Describe the bug Tried to use a record as a one way view model but it seems impossible. Microsoft.UI.Xaml.Markup.Compiler generates code ...
Read more >
firebase_admin.auth module | Firebase - Google
ValueError – If the specified user properties are invalid. FirebaseError – If an error occurs while creating the user account.
Read more >
pylon SDK Samples Manual | Basler Product Documentation
On Linux or macOS operating systems, the source code for the samples can be copied from the archive to any location on the...
Read more >
Error codes – Quickbase Help
Code Message Possible Cause 0 No error No error 1 Unknown error 4 Bad ticket
Read more >
Records - C# reference
When you declare a primary constructor on a record, the compiler generates public properties for the primary constructor parameters.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found