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

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

Open
p5ych08illy opened this issue Jan 23, 2025 · 7 comments
Open

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

p5ych08illy opened this issue Jan 23, 2025 · 7 comments

Comments

@p5ych08illy
Copy link

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

@T-Gro
Copy link
Member

T-Gro commented Jan 23, 2025

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?

@p5ych08illy
Copy link
Author

Hi @T-Gro ,

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

FSharpClassLibrary4.zip

@T-Gro
Copy link
Member

T-Gro commented Jan 23, 2025

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?

@p5ych08illy
Copy link
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.

@vzarytovskii
Copy link
Member

vzarytovskii commented Jan 23, 2025

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>.

@p5ych08illy
Copy link
Author

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

@vzarytovskii
Copy link
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.

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

No branches or pull requests

3 participants