OrleansContrib/Orleans.Providers.MongoDB

Stat can't have Ulong or Uint fields

shersh opened this issue · 4 comments

I know, MongoDb does not support UInt64 and UInt32 types.
But this provider allows save state with ulong field as long and can't read this if field will be overflowed for long.

For example

public class MyGrain : Grain<MyGrain.MyState>, IMyGrain
{
     public class MyState 
     {
           public ulong SomeValue {get;set;}
     }

    public override async Task OnActivateAsync() 
    {
          State.SomeValue = 18446744069448139334; 
     }
}

It will cast to long during saving to db.
But will be crashed when activating grain again.

But there is no solution I guess

@SebastianStehle why?
If you cast ULong to long and after cast it to ULong - you will get rigth number. Problem is in deserialization from bson document to model.

The provider uses JSON.NET for serialization and then converts it to BSON: https://github.com/OrleansContrib/Orleans.Providers.MongoDB/blob/master/Orleans.Providers.MongoDB/StorageProviders/JsonBsonConverter.cs

If you have a solution you can provide a PR for it.

I recommend to provide a custom serializer for this case.