Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Null reference exception in zero formatter #115

Open
AminSojoudi opened this issue Dec 19, 2019 · 0 comments
Open

Null reference exception in zero formatter #115

AminSojoudi opened this issue Dec 19, 2019 · 0 comments

Comments

@AminSojoudi
Copy link

AminSojoudi commented Dec 19, 2019

I'm getting a null reference exception from Zeroformatter, I can not find why is this happening.
I'm just trying to read an object from MongoDb which has a ZeroFormattable attribute. It has nothing to do with MongoDB, I'm just using Zeroformatter for other purposes (caching in Redis).

Dotnet core 2.2
Zeroformatter 1.6.4
On Linux Docker image

Here is the error log:

System.NullReferenceException

Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an object.
   at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.GameServer.Models.User.set_Id(String )
   at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeClass(BsonDeserializationContext context)
   at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
   at MongoDB.Bson.Serialization.Serializers.SerializerBase`1.MongoDB.Bson.Serialization.IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
   at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize(IBsonSerializer serializer, BsonDeserializationContext context)
   at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
   at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)
   at MongoDB.Driver.Core.Operations.CursorBatchDeserializationHelper.DeserializeBatch[TDocument](RawBsonArray batch, IBsonSerializer`1 documentSerializer, MessageEncoderSettings messageEncoderSettings)
   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.CreateCursorBatch(BsonDocument commandResult)
   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.CreateCursor(IChannelSourceHandle channelSource, BsonDocument commandResult)
   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.FindOperation`1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.FindOperation`1.ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
   at MongoDB.Driver.OperationExecutor.ExecuteReadOperationAsync[TResult](IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperationAsync[TResult](IClientSessionHandle session, IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
   at GameServer.Services.LeaderboardService.SaveScoreToLeaderboards(Game game)

The User Model is This:

    [BsonDiscriminator("MyUser")]
    [ZeroFormattable]
    public class User
    {
        [Index(0)]
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        public virtual string Id { get; set; }
        [Index(1)]
        public virtual string Username { get; set; }
        [Index(2)]
        public virtual string ActiveDeviceId { get; set; }
        [Index(3)]
        public virtual string Email { get; set; }
        [Index(4)]
        public virtual int Coin { get; set; }
        [Index(5)]
        public virtual int Gem { get; set; }
        [Index(6)]
        public virtual int Cup { get; set; } = -1;
        [Index(7)]
        public virtual int Ticket { get; set; }
        [Index(8)]
        public virtual int GoldenTicket { get; set; }
        [Index(9)]
        public virtual int Level { get; set; }
        [Index(10)]
        public virtual int XP { get; set; }
        [Index(11)]
        public virtual string ActiveKitchen { get; set; }
        [Index(12)]
        public virtual int ActiveKitchenMission { get; set; } = 0;
        [Index(13)]
        public virtual Dictionary<string, Kitchen> UserKitchens { get; set; } = new Dictionary<string, Kitchen>();
        [Index(14)]
        public virtual DateTime CreatedAt { get; set; }
        [Index(15)]
        public virtual DateTime UpdatedAt { get; set; }
        [Index(16)]
        public virtual int GasCapsules { get; set; }
        [Index(17)]
        public virtual List<KitchenInventoryItem> KitchenInventory { get; set; } = new List<KitchenInventoryItem>();
        [Index(18)]
        public virtual List<Friend> FriendsList { get; set; }
        [Index(19)]
        public virtual List<FriendRequest> FriendRequestsReceived { get; set; }
        [Index(20)]
        public virtual UserClan Clan { get; set; }
        [Index(21)]
        public virtual string ProfilePic { get; set; }
        [Index(22)]
        public virtual List<UserPowerup> Powerups { get; set; } = new List<UserPowerup>();
        [Index(23)]
        public virtual UserDaubChest DaubChest { get; set; }
        [Index(24)]
        public virtual int LastSuccessDaubChest { get; set; }
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant