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

F# Discriminative Unions not serializing correctly when being returned from grains #9258

Open
WesleySkeen opened this issue Dec 2, 2024 · 6 comments

Comments

@WesleySkeen
Copy link
Contributor

WesleySkeen commented Dec 2, 2024

I believe there is an issue with the fsharp discrimitive unions and the orleans dotnet 9 grain serializer

Here is a repo were this can be reproduced
https://github.com/WesleySkeen/orleans-fsharp-dotnet9/tree/main

I have this type that gets returned from the grain

Image

Here is the grain interface and its implementation

Image

I have hardcoded the result to demonstrate the issue.

I believe the issue lies in the responseCopier of the GrainMethodInvoker class

Here is the response before the responseCopier function gets called

Image

and here is the result after

Image

As you can see, the content of the discrimitive union is now null

@WesleySkeen
Copy link
Contributor Author

This works as expected when targeting dotnet 8

@ReubenBond
Copy link
Member

@WesleySkeen does it work when targeting Orleans v9.0.1 with .NET 8.0? Could it be an internal representation breakage in F# 9.0?

@WesleySkeen
Copy link
Contributor Author

@ReubenBond I just checked there, updated all 'Microsoft.Orleans.*' packages int he solution to 9.0.1. Does not work. So your thought is correct I think

@ReubenBond
Copy link
Member

Orleans v9.0.1 is compatible with .NET 8.0 and .NET 9.0 - does it work with 8 and not 9? This will need further investigation

@WesleySkeen
Copy link
Contributor Author

WesleySkeen commented Dec 3, 2024

@ReubenBond apologies, here is a table of Orleans versions against dotnet versions and if it works or not. Looks like an issue with Orleans from this

Orleans Dotnet Works
8.2.0 .NET 8.0 Works
8.2.0 .NET 9.0 Works
9.0.1 .NET 8.0 Does Not Work
9.0.1 .NET 9.0 Does Not work

The repo I linked can be used to do some tests if needed

@gfix
Copy link
Contributor

gfix commented Dec 20, 2024

Hi,

This is indeed an Orleans issue, but there is a known workaround. The reason for this is the change in the Orleans source generator introduced in #9095. There we go from serializing the public property Item emitted by the F# compiler to serializing the internal backing field item. Thus, the workaround is to make internal visible to the project being target for code generation. I this case, adding

[<InternalsVisibleTo("Host")>]
do ()

in HelloWorld.fs makes the code work again. In this particular case this is a regression, but over all this is currently necessary. Say you were to change the type HelloWorldResult to

[<GenerateSerializer>]
type HelloWorldResult =   
    | Failed
    | Completed of string

this would fail at compile time in the Orleans source generator. This is reported in issue #8717. I see now, @ReubenBond, that you answered me the same day I asked for where to document this 🙈 I will try to document this at the start of next year.

Can we solve this somehow? The current approach using the Roslyn APIs for code analysis might not be the best fit for F#, since we rely on F# compiler implementation details when discovering what to generate serialization code for. I don't know what we could do instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants