Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinaryFormatter causing me grief #384

Closed
OldManMeta opened this issue Jun 26, 2022 · 3 comments
Closed

BinaryFormatter causing me grief #384

OldManMeta opened this issue Jun 26, 2022 · 3 comments

Comments

@OldManMeta
Copy link

Description

Hi there - I wrote a number of libraries a while back that reference and use your awesome project. Those references were based on 0.9.0 version of your libs, with Redis as the provider.

Creating a new solution in .net 6 core - I tried to upgrade to libs 1.6.0 versions.

I get the following error when calling into the solution:

EasyCaching.Core.EasyCachingNotFoundException: Can not find the matched serializer instance, serializer name is IMPCore at EasyCaching.Redis.DefaultRedisCachingProvider..ctor(String name, IEnumerable1 dbProviders, IEnumerable1 serializers, RedisOptions options, RedisLockFactory factory, ILoggerFactory loggerFactory) at EasyCaching.Redis.RedisOptionsExtension.<AddServices>b__3_1(IServiceProvider x) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired) at lambda_method11(Closure , IServiceProvider , Object[] ) at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass7_0.<CreateActivator>b__0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

If I revert back to the 0.9 libs, i get issues with the BinaryFormatter with .Net Core 6 where they are now obsolete.

Having tried to use MessagePack, JSON etc as serializer, I am still seeing the same BinaryFormatter issues, which are on the deserialize, rather than the serialize oddly enough.

Any suggestions on how to get around these issues?

This is the config I am trying to use:

`

builder.Services.AddEasyCaching(options =>
{
options.UseRedis(redisConfig =>
{
redisConfig.DBConfig.Endpoints.Add(new ServerEndPoint(RedisHostAddress, RedisPort));

    if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Production")
    {
        //Set password for connection
        if (!string.IsNullOrEmpty(RedisServerPassword))
        {
            redisConfig.DBConfig.AbortOnConnectFail = false;
            redisConfig.DBConfig.IsSsl = true;
            redisConfig.DBConfig.ConnectionTimeout = 5000;

            redisConfig.DBConfig.Password = RedisServerPassword;
        }

    }

    //Allow the admin optioons
    redisConfig.DBConfig.AllowAdmin = true;


},
"MyStore");//.WithMessagePack();//Channel name

});
`

@catcherwong
Copy link
Member

@OldManMeta Thanks for your interest in this project.

Please take a look on #370 .

@OldManMeta
Copy link
Author

hi @catcherwong - thanks very much for the response and the direction.

Given that I don't really need the binaryformatter at all, what is the optimal config for Redis in 1.6.0 that doesn't use it?

Thanks again.
Cheers

@catcherwong
Copy link
Member

Just use another serializer to replace binaryformatter, such as MessagePack, Json, and Probobuf.

Here is a sample use MessagePack.

option.UseRedis(config =>
{
    config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
    
    // specify the SerializerName 
    config.SerializerName = "mymsgpack";
}, "redis1")

// using MessagePack to serialize caching data.
.WithMessagePack("mymsgpack");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants