Alachisoft / NCache

NCache: Highly Scalable Distributed Cache for .NET
http://www.alachisoft.com
Apache License 2.0
647 stars 123 forks source link

.Net 6.0 NCacheDistributedCache.CheckAndInitializeCache Fails #68

Open MaddMugsy opened 2 years ago

MaddMugsy commented 2 years ago

I've just ported several .Net 5.0 APIs that use NCache for distributed caching to .Net 6.0, and while they worked fine locally, they can now all generate the same error right on startup when deployed to IIS. However, the error seems to be appearing randomly (not all APIs will have it) and can be fixed by restarting IIS / redeploying a failing API. This was not an issue in .Net 5.0.

Tested with NCache 5.2.0.0 and 5.2.1.0.

Upon failure the swagger page for an API reads as follows:

HTTP Error 500.30 - ASP.NET Core app failed to start Common solutions to this issue: The app failed to start The app started but then stopped The app started but threw an exception during startup Troubleshooting steps: Check the system event log for error messages Enable logging the application process' stdout messages Attach a debugger to the application process and inspect For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265

Here is the error from the event log. It looks like NCacheDistributedCache.CheckAndInitializeCache() is the cause.

System.Configuration.Provider.ProviderException: Object reference not set to an instance of an object. ---> System.Configuration.Provider.ProviderException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Alachisoft.NCache.Common.Logger.NCacheLogger.Debug(String message) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogDebug(String message) --- End of inner exception stack trace --- at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.RaiseException(Exception exc) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogError(Exception exception) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogDebug(String message) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.CheckAndInitializeCache() --- End of inner exception stack trace --- at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.RaiseException(Exception exc) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogError(Exception exception) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.CheckAndInitializeCache() at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache..ctor(IOptions1 options) at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 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.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) 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.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass5_0.<UseMiddleware>b__0(RequestDelegate next) at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build() at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) Unhandled exception. System.Configuration.Provider.ProviderException: Object reference not set to an instance of an object. ---> System.Configuration.Provider.ProviderException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Alachisoft.NCache.Common.Logger.NCacheLogger.Debug(String message) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogDebug(String message) --- End of inner exception stack trace --- at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.RaiseException(Exception exc) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogError(Exception exception) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogDebug(String message) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.CheckAndInitializeCache() --- End of inner exception stack trace --- at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.RaiseException(Exception exc) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogError(Exception exception) at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.CheckAndInitializeCache() at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache..ctor(IOptions1 options) at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 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.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) 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.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass5_0.<UseMiddleware>b__0(RequestDelegate next) at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build() at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)

Related issue here: https://github.com/Alachisoft/NCache/issues/54

Dan-Ahmed commented 2 years ago

@MaddMugsy, I have already forwarded this to our engineering team and they will review this on their end.