OrleansContrib / Orleans.Providers.MongoDB

A MongoDb implementation of the Orleans Providers: Membership, Storage and Reminders.
MIT License
105 stars 44 forks source link

Stat can't have Ulong or Uint fields #89

Closed shersh closed 3 years ago

shersh commented 3 years ago

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.

SebastianStehle commented 3 years ago

But there is no solution I guess

shersh commented 3 years ago

@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.

SebastianStehle commented 3 years ago

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.

SebastianStehle commented 3 years ago

I recommend to provide a custom serializer for this case.