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

Issue with consuming DLL when using LangVersion set to 8.0 with .NET SDK 9 #18003

Open
ljb opened this issue Nov 14, 2024 · 1 comment
Open
Labels
Bug Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. Regression
Milestone

Comments

@ljb
Copy link

ljb commented Nov 14, 2024

Recently I changed a large F# code base to work with .NET SDK 9 and F# 9. To start with I didn't change LangVersion which gave me a lot of errors of the type:

    FSC : error FS0229: Error opening binary file 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll': Error reading/writing metadata for the F# compiled DLL 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll'. Was the DLL compiled with an earlier version of the F# compiler? (error: 'u_ty - 1/B, byte = 1').
    FSC : error FS3160: Problem reading assembly 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll': The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: Error opening binary file 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll': Error reading/writing metadata for the F# compiled DLL 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll'. Was the DLL compiled with an earlier version of the F# compiler? (error: 'u_ty - 1/B, byte = 1').)

Repro steps
Use .NET SDK 9.

Have a project that has LangVersion set to 8.0:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <LangVersion>8.0</LangVersion>
        <TargetFramework>net9.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <Compile Include="Library.fs"/>
    </ItemGroup>

</Project>

Have the following code in Library.fs:

module MyModule

    let convert (lookup: 'a -> 'b) (id: 'a): unit =
        lookup id
        |> Option.ofObj
        |> ignore

Have a project that has a project reference to the project above. It doesn't matter what LangVersion or TargetFramework that project has.

A zip-file with this example is attached. Running dotnet build results in errors.
fsharp-error.zip

Expected behavior

It is possible to build the projects without errors.

Actual behavior

I get errors of the following type:

    FSC : error FS0229: Error opening binary file 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll': Error reading/writing metadata for the F# compiled DLL 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll'. Was the DLL compiled with an earlier version of the F# compiler? (error: 'u_ty - 1/B, byte = 1').
    FSC : error FS3160: Problem reading assembly 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll': The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: Error opening binary file 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll': Error reading/writing metadata for the F# compiled DLL 'C:\repos\fsharp-test\ClassLibrary1\obj\Debug\net8.0\ref\ClassLibrary1.dll'. Was the DLL compiled with an earlier version of the F# compiler? (error: 'u_ty - 1/B, byte = 1').)

Known workarounds

Set LangVersion to 9.0 or use .NET SDK 8

Related information

A similar problem was discussed in #14313.

This issue is somewhat different I think. Here you get errors even if the same target framework is used for both projects. It is only LangVersion that cause the problem.

With .NET SDK 8.0.403 it works with LangVersion set both to 7.0 and 8.0.

I have a really large F# code base, and is only the kind of construct that I have in Library.fs that causes problems.

  • Windows 11
  • .NET SDK 9.0.100
@vzarytovskii
Copy link
Member

Some feature which changes picked data, will be easy to pinpoint. Not sure how to mitigate though.

@psfinaki psfinaki added Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. and removed Needs-Triage labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. Regression
Projects
Status: New
Development

No branches or pull requests

4 participants