Coder Social home page Coder Social logo

Comments (12)

ismcagdas avatar ismcagdas commented on May 24, 2024 1

Thanks @freedyang I have reproduced this problem

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 24, 2024

Does this work https://stackoverflow.com/a/66963611 ?

from aspnetboilerplate.

freedyang avatar freedyang commented on May 24, 2024

It works for AbpRedisCache, but not for AbpPerRequestRedisCache:

        services.AddControllersWithViews(options =>
        {
            options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute());
            options.AddAbpHtmlSanitizer();
        })
        .AddJsonOptions(options => 
        {
            options.JsonSerializerOptions.Converters.Add(new CustomJsonConverterForType()); 
        });

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 24, 2024

Could you replace DefaultRedisCacheSerializer with the one in this PR and see if it works ? https://github.com/aspnetboilerplate/aspnetboilerplate/pull/6887/files

from aspnetboilerplate.

freedyang avatar freedyang commented on May 24, 2024

After replacing the default implementation service of DefaultRedisCacheSerializer, it still does not work:

ReplaceService:

Configuration.ReplaceService<IRedisCacheSerializer, DefaultRedisCacheSerializerExtensions>(DependencyLifeStyle.Transient);

DefaultRedisCacheSerializerExtensions:

public class DefaultRedisCacheSerializerExtensions : IRedisCacheSerializer, ITransientDependency
{
    public virtual object Deserialize(RedisValue objbyte)
    {
        var serializerSettings = new JsonSerializerOptions();
        serializerSettings.Converters.Insert(0, new Abp.Json.SystemTextJson.AbpDateTimeConverter());

        var cacheData = AbpCacheData.Deserialize(objbyte);

        return cacheData.Payload.FromJsonString(
            Type.GetType(cacheData.Type, true, true),
            serializerSettings);
    }

    public virtual RedisValue Serialize(object value, Type type)
    {
        var json = AbpCacheData.Serialize(value);
        return JsonSerializer.Serialize(json, new JsonSerializerOptions
        {
            Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
        });
    }
}

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 24, 2024

@freedyang I couldn't reproduce this problem on a new project, is it possible to share a reproduction project ?
Could oyu also try to change DefaultRedisCacheSerializerExtensions as shown below ?

public class DefaultRedisCacheSerializerExtensions : IRedisCacheSerializer, ITransientDependency
{
    public virtual object Deserialize(RedisValue objbyte)
    {
        var serializerSettings = new JsonSerializerOptions();
        serializerSettings.Converters.Insert(0, new Abp.Json.SystemTextJson.AbpDateTimeConverter());
		serializerSettings.Converters.Add(new CustomJsonConverterForType()); 

        var cacheData = AbpCacheData.Deserialize(objbyte);

        return cacheData.Payload.FromJsonString(
            Type.GetType(cacheData.Type, true, true),
            serializerSettings);
    }

    public virtual RedisValue Serialize(object value, Type type)
    {
        var json = AbpCacheData.Serialize(value);
        return JsonSerializer.Serialize(json, new JsonSerializerOptions
        {
            Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
        });
    }
}

from aspnetboilerplate.

freedyang avatar freedyang commented on May 24, 2024

@ismcagdas This bug is not related to the DefaultRedisCacheSerializer, it cause by AbpCacheData.Serialize(value):

  1. Abp.Runtime.Caching.Redis.AbpRedisCache.Serialize(Object value, Type type)
  2. Abp.Runtime.Caching.Redis.DefaultRedisCacheSerializer.Serialize(Object value, Type type)
  3. Abp.Runtime.Caching.AbpCacheData.Serialize(Object obj, Boolean withAssemblyName)
  4. Abp.Json.JsonExtensions.ToJsonString(Object obj, Boolean camelCase, Boolean indented)
  5. System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
  6. Throw the System.NotSupportedException...

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 24, 2024

Is it possible to provide a reproduction project ?

from aspnetboilerplate.

freedyang avatar freedyang commented on May 24, 2024

ASP.NET Zero v13.1.0-rc.1, WebCoreModule: UseRedis & UsePerRequestRedisCache

Configuration.Caching.UseRedis(options =>
    {
        options.ConnectionString = _appConfiguration["Abp:RedisCache:ConnectionString"];
        options.DatabaseId = -1
    },
    usePerRequestRedisCache: true
);

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 24, 2024

Is the app failing when you run it or does this happen in a specific case ?

from aspnetboilerplate.

freedyang avatar freedyang commented on May 24, 2024

if set UsePerRequestRedisCache = true, then each time login, will throw above exceltion.

The app won't crash and can run normally.

from aspnetboilerplate.

freedyang avatar freedyang commented on May 24, 2024

If back to UseNewtonsoft, then everthing is ok, no exceptions thrown:

CoreModule:

JsonExtensions.UseNewtonsoft = true;

from aspnetboilerplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.