mbraceproject / FsPickler

A fast multi-format message serializer for .NET
http://mbraceproject.github.io/FsPickler/
MIT License
326 stars 51 forks source link

Version 5.3.2 incompatible to VS 2017 #120

Closed luithefirst closed 4 years ago

luithefirst commented 4 years ago

An update to FsPickler to 5.3.2 breaks the build of our solution in VS 2017 / MSBuild 15 with Visual F# Tools 10.2 for F# 4.5 15.8.0.0. The prior version FsPickler 5.3.1 works fine.

Steps to reproduce:

  1. Create new F# .net 4.7.2 or 4.8 Windows Console application
  2. Manage Nuget packages -> add a reference to FsPickler 5.3.2

Adding the assembly reference breaks the build with the following error:

1>FSC: error FS0229: Error opening binary file 'C:\- Work\ConsoleApplication1\packages\FsPickler.5.3.2\lib\net45\FsPickler.dll': Error reading/writing metadata for the F# compiled DLL 'C:\- Work\ConsoleApplication1\packages\FsPickler.5.3.2\lib\net45\FsPickler.dll'. Was the DLL compiled with an earlier version of the F# compiler? (error: 'lookup_uniq in table istrings out of range, n = 108, sizeof(tab) = 1').
1>FSC: error FS3160: Problem reading assembly 'C:\- Work\ConsoleApplication1\packages\FsPickler.5.3.2\lib\net45\FsPickler.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:\- Work\ConsoleApplication1\packages\FsPickler.5.3.2\lib\net45\FsPickler.dll': Error reading/writing metadata for the F# compiled DLL 'C:\- Work\ConsoleApplication1\packages\FsPickler.5.3.2\lib\net45\FsPickler.dll'. Was the DLL compiled with an earlier version of the F# compiler? (error: 'lookup_uniq in table istrings out of range, n = 108, sizeof(tab) = 1').)

In VS 2019 / MSBuild 16 the solution builds as intended.

When I build FsPickler locally it results in the same error. By reverting the recent commits I could figure out that the changes in https://github.com/mbraceproject/FsPickler/commit/8d5fd5cf5ef0b97737e3a4bdceb615a61a81e77f "Use assembly load context when loading assemblies" have introduced this issue.

For me, it's not clear why the changes result in this error and the output of the FSC seems to be misleading.

It does not look like that a restriction to MSBuild 16 was intended. It would be great if someone could have a look at this and find a compatible solution.

eiriktsarpalis commented 4 years ago

This looks like an F# metadata read error. @cartermp can this be expected with older versions of the compiler?

cartermp commented 4 years ago

This is a forwards-compat problem. In 5.3.2 did you use anonymous records anywhere? That will add new metadata to the F# metadata blob and make the .dll not consumable by older compilers.

eiriktsarpalis commented 4 years ago

Yes, looks like it is being used for internals. The addition can be seen in the commit linked in the OP.

cartermp commented 4 years ago

Yep. Nothing can be done to work around this for older compilers, unfortunately. It's either not supported for F# 4.5 or lower, or the package will need to update to no longer use anonymous records.

eiriktsarpalis commented 4 years ago

In that case I'd be inclined to say that it probably doesn't make sense to support older compiler versions. While I could replace that particular anonymous record with a tuple, we have no good way of guarding against future regressions.

luithefirst commented 4 years ago

Right, the new code is using an anonymous record and this perfectly explains the compiler error.

Thanks for the analysis and clarification of the development future.

thomasd3 commented 4 years ago

I’m having that issue while using the .net 5 preview 8 that was released a day or so ago, and the latest F# compiler. I moved back the project to .net core 3.1 and had the issue again, while .net 5 is installed. That’s on MacOS. I haven’t tried .net 4.7 since I didn’t use it in years.

eiriktsarpalis commented 4 years ago

Are you able to build from the command line? I believe you mentioned that the issue only happened on VS mac, so maybe the tooling there is out of date?

cartermp commented 4 years ago

VSMac tooling is out of date. It uses Mono at design time which is still stuck on F# 4.5

thomasd3 commented 4 years ago

I think there is a combination of problems:

using:

I get the following: