Closed varon closed 6 years ago
Reporting that the workaround of writing structs by hand in a pre-F# 4.1 does allow working around the issue, but isn't an elegant solution at all.
@varon this library has not been updated to take struct records into account. I pushed commit https://github.com/mbraceproject/FsPickler/commit/8b419014c64af6984a564197e8495624edd67aa7 so that the library reports proper error messages on struct record/union serialization.
Thanks for the super fast response, @eiriktsarpalis!
Is this still being actively maintained? Is there any timeframe on an update? What would be involved in getting this up and running?
@varon A group of us co-maintain the mbrace repos, so we can help guide you if you would like to contribute a PR (it would be great to have you on board).
It looks like it's mostly a matter of adjusting the codegen to take structnes into account. That can be quite painful though - you have to take extra addresses quite often when accessing fields and so on
@dsyme - Thanks for the incredibly welcoming gesture.
I can shuffle some time around to get a PR for this together. It seems like a great opportunity to get some advanced mentorship on what seems to be a fairly clean but challenging codebase. I'll be happy to give it a bash if you can judge it's doable in a reasonable amount of time (for someone unfamiliar with the library internals).
I can probably figure out what to do, but a rough outline of the process would be great.
From glancing at the code
First get things working with the define EMIT_IL off (assuming that non-struct tests pass ok with that). It could be that everything just works
Next look at the EMIT_IL cases. will need to look more closely at that
@dsyme - Thanks, I'll take a look.
I'll need to add a reference to System.ValueTuple
for the struct tuples to work.
We may also need to upgrade F# 4.1 for that.
How would you like this to be done? NuGet? F# version selector?
I've attempted this in what seems to be a reasonable way: https://github.com/varon/FsPickler/commit/405a883ec1a413f7023bbbf86c568a671f4e6473
If it helps, you can view the PR in progress here: https://github.com/varon/FsPickler/commits/fsharp41-compat
@varon Great job so far, looking forward to the PR :)
I've seen that several PR have been merged to solve this bug. But it's not published on nuget yet ? Is there still work on this issue ?
Fixed in FsPickler 4.0
Description
Trying to serialise a simple record type introduced in F# 4.1, which is marked as a struct fails.
Repro code
Expected behavior
Ideally it should work, or provide a clearer error.
Actual behavior
From this example, an exception is thrown:
I observed a lot of VERY obscure errors while attempting to serialise fairly complex F# 4.1 types in a larger project. These were non-determinstic, and included:
System.Runtime.InteropServices.SEHException: 'External component has thrown an exception.'
and
Managed Debugging Assistant 'FatalExecutionEngineError' : 'The runtime has encountered a fatal error. The address of the error was at 0x246d6a66, on thread 0x8d78. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.'
and
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Finally, under a mono server which actually helped point me in the right direction, I received the following error in the larger project:
Related information
Workarounds: I'm going to try writing struct records by hand for now, as we did prior to 4.1.