dotnetcore / EasyCaching

:boom: EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
MIT License
1.96k stars 323 forks source link

MessagePack.MessagePackSerializationException exception #372

Closed Almis90 closed 2 years ago

Almis90 commented 2 years ago

Description

I'm getting the exception "MessagePack.MessagePackSerializationException" when I call "TrySetAsync" with Disk provider even though I chose to use JSON serializer. When I use InMemory then it doesn't throw any exceptions.

Steps to Reproduce

  1. Set JSON as my serializer
  2. Call provider.TrySetAsync

Related code

This my DI

            services.AddEasyCaching(option =>
            {
                option.UseDisk(config =>
                {
                    config.DBConfig = new DiskDbOptions { BasePath = Path.GetTempPath() };
                    config.SerializerName = "json";
                }, "disk").WithJson("json");
            });

this is how I call provider.TrySetAsync

            await _provider.TrySetAsync(nameof(ListLanguages) + extraKey, response, TimeSpan.FromDays(1));

Expected behavior: [What you expected to happen] I expected it to save successfully or at least give me another error that is not related to MessagePack because I'm not using it.

Actual behavior: [What actually happened] I getting an exception that MessagePack serializer failed

Specifications

catcherwong commented 2 years ago

@Almis90 Thanks for your interest in this project.

I'm very sorry for taking so long to reply to you.

For disk provider, we use MessagePack to serializer/deserializer the data, SerializerName is useless here.

It seems that the response can not be serialized. Could you show more information for this response?

Almis90 commented 2 years ago

@Almis90 Thanks for your interest in this project.

I'm very sorry for taking so long to reply to you.

For disk provider, we use MessagePack to serializer/deserializer the data, SerializerName is useless here.

It seems that the response can not be serialized. Could you show more information for this response?

No problem at all, at the end I switched to LiteDB thinking it would solve my issue but it didn't. The problem was that I was trying to serialize a class from a library, for some reason it was not serializing two properties (but at least it was not throwing exception), so I mapped it to my own class and it worked.