Skip to content

Discriminated union .Is* properties causing compile time error #18263

Open

Description

@p5ych08illy

Compile time error since Visual Studio update: "Error in pass2 for type Foo, error: duplicate entry 'get_IsSZ' in method table."

Repro steps

Create blank F# class library

namespace FSharpClassLibrary4

module Say =
    let hello name =
        printfn "Hello %s" name

    type Foo = 
    | SZ
    | STZ
    | ZS
    | ASZ

Expected behavior

The example compiles successfully.

Actual behavior

Compile time error:
"A problem occurred writing the binary 'C:...\FSharpClassLibrary4\FSharpClassLibrary4\obj\Debug\net6.0\FSharpClassLibrary4.dll': Error in pass2 for type FSharpClassLibrary4.Say, error: Error in pass2 for type Foo, error: duplicate entry 'get_IsSZ' in method table"

Known workarounds

  1. Use Language version 8
  2. Rename SZ type not to begin with SZ

Related information

.NET SDK: 9.0.102
Visual Studio: 17.12.4

Activity

  1. added this to the Backlog milestone on Jan 23, 2025
  2. T-Gro commented on Jan 23, 2025

    @T-Gro
    Member

    Hi @p5ych08illy ,

    could you also share a project file for this repro?
    I tried the posted sample (.NET 9 SDK) and did not get the mentioned error.

    Is this a standalone repro, or is there additional code in the same file?

  3. p5ych08illy commented on Jan 23, 2025

    @p5ych08illy
    Author

    Hi @T-Gro ,

    I attached the project. It contains only the code snippet I provided above.

    FSharpClassLibrary4.zip

  4. T-Gro commented on Jan 23, 2025

    @T-Gro
    Member

    Do you by any chance have a Directory.props or Directory.targets in the folder hiearchy?

    I tried a dotnet build of the project and it passes at me.
    I also enforced the SDK via an added global.json file to be "version": "9.0.102" and it also passes.

    Among others, your file specified a net9 target framework, but the error message below does have net6.0 in it - which gives me the idea of some parent folder affecting msbuild properties perharps?

  5. p5ych08illy commented on Jan 23, 2025

    @p5ych08illy
    Author

    I do not have any props or targets file.

    I can successfully compile the project with dotnet build too.

    If I try msbuild from a Developer Command prompt, I get the same error: "FSC : error FS2014: A problem occurred writing the binary 'obj\Debug\net9.0\refint\FSharpClassLibrary4.dll': Error in pass2 for type FSharpClassLibrary4.Say, error: Error in pass2 for type Foo, error: duplicate entry 'get_IsSZ' in method table [c:...\FSharpClassLibrary4\FSharpClassLibrary4\FSharpClassLibrary4.fsproj]"

    I tried a lot of SDK and .NET version and I don't remember where I copied that error message (net6.0) from.

  6. vzarytovskii commented on Jan 23, 2025

    @vzarytovskii
    Member

    17.12 had an issue with ref assemblies and generating case testers. You can either update to latest (17.13 probably), or turn off reference assemblies <ProduceReferenceAssembly>false</ProduceReferenceAssembly>.

  7. p5ych08illy commented on Jan 24, 2025

    @p5ych08illy
    Author

    I can not test the Preview version (17.13) right now but the <ProduceReferenceAssembly>false</ProduceReferenceAssembly> did not help.

  8. vzarytovskii commented on Jan 24, 2025

    @vzarytovskii
    Member

    I can not test the Preview version (17.13) right now but the <ProduceReferenceAssembly>false</ProduceReferenceAssembly> did not help.

    Hm, that is weird. This should've turned refassemblies emit off completely.

  9. self-assigned this
    on Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.

Type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions