Serializing and deserializing f# functions is not supported
See original GitHub issueToday i tried to do make a model something like this
[<CLIMutable>]
type Product =
{
Id: int
Name: string
//PrinterKey: Expression<Func<Item,obj>>
ImposerKey: obj -> obj
}
When i deserialized it from database, below exception was thrown
Newtonsoft.Json.JsonSerializationException: 'Could not create an instance of type Microsoft.FSharp.Core.FSharpFunc`2[System.Object,System.Object]. Type is an interface or abstract class and cannot be instantiated. Path 'Products[0].ImposerKey', line 1, position 133.'
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Why does System.Text.Json throw a ` ...
Your code is failing during serialization not deserialization because you are catching some inner exception and trying to serialize it with ...
Read more >Serde serialize to not supported type
I'm implementing a serde Serializer Serializer in serde - Rust for a binary format that do not distinguish between signed and unsigned integer ......
Read more >Asp.net identity System.NotSupportedException
Hi so im using the method FindUserById tfrom asp.net identity and i get this error ill attach the code ** Controller method ...
Read more >BinaryFormatter serialization methods are obsolete and ...
Serialize and Deserialize methods on BinaryFormatter, Formatter, and IFormatter are now obsolete as warning. Additionally, BinaryFormatter ...
Read more >net 5.0 BinaryFormatter not supported - Help
I tried to upgrade my web api to .net 5.0 and get the exception 'BinaryFormatter serialization and deserialization are disabled within this application....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I am assuming you solved your issue, if it happened to be the case that you still need to serialize or deserialize functions, then just use a
byte[]as the data format to store the function with FsPickler for converting between the bytes and functions. This way you don’t need to integrate FsPickler with this library internallyYour business logic should be in your code, not in your storage system. The only reason you would store arbitrary filters inside the database, is to be able to update them by hand (without the application) which I don’t think you actually want.
You would put this kind of logic in place where you are reading the values from the database in a
wherequery:otherwise if you really needed to store F# filters, I suggest you use a simple embedded DSL that you can serialize to the database (then you will be doing what LiteDB is doing for you now):
You will also need to evaulate the expr yourself against dynamic record values from the database