What is required to make F# discriminated unions work with Orleans 7?

84 Views Asked by At

I'm attempting to add an F# discriminated union type to an Orleans 7 project.

[<GenerateSerializer>]
type SmtpServerResult =
    | Pending
    | Error of ErrorMessage
    | Complete of SmtpServer array

When I compile the project, I get this compile error from the Orleans codegen file MyNamespace.Codegen.orleans.g.cs(20281,179): Error CS0122 : 'SmtpServerResult._Pending' is inccessible due to its protection level

I attempted to review the codegen file to get more details but can't find it. I'll keep looking it might in temp or something.

Is there something I can add to my type that would make the cases accessible to the Orleans code generator?

Update
I ran another build with detailed log output. That shows a full path for the codegen file that has the compile error. However, that path is not valid. I suspect that the file is only in memory at that point and never gets saved due the build error.

Update 2
I tried a few variations on my type and discovered that if I provide a data type for the Pending case (e.g. Pending of int), the code generator is successful. So there may be something about DU cases that don't carry any data that is either a generator bug or simply not supported.

1

There are 1 best solutions below

0
Matthew MacFarland On

Based on my own trial and error, I'm pretty sure the answer is that the DU cases must carry some data. While Option works fine with the Orleans serializer and it's None case has no data, the serializer has specific handling for that type. But, for any custom DU types it seems to be necessary to include data with each case to avoid the codegen errors.

Related Questions in F#