Reputation: 844
(My previous question/issue was not specific enough. Hence the complete rewrite.)
Issue: ServiceStack 4.0.16 does not work with Redis.
Steps to recreate:
container.Register(c => new PooledRedisClientManager("localhost:6379")); container.Register(c => (ICacheClient)c.Resolve() .GetCacheClient()) .ReusedWithin(Funq.ReuseScope.None);
Open the Event Viewer and go to Applications and you should see three Errors
1. Failed to initialize the AppDomain:/LM/W3SVC/24/ROOT
Exception: System.Runtime.Serialization.SerializationException
Message: Type 'ServiceStack.DispsableTracker' in assembly 'ServiceStack, Version=4.0.16.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
StackTrace: at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)
2. An error occurred while trying to start an integrated application instance.
Exception: System.Runtime.Serialization.SerializationException
Message: Type 'ServiceStack.DispsableTracker' in assembly 'ServiceStack, Version=4.0.16.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
StackTrace: at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.ApplicationManager.GetAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.ApplicationManager.CreateObjectInternal(String appId, Type type, IApplicationHost appHost, Boolean failIfExists, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.ProcessHost.StartApplication(String appId, String appPath, Object& runtimeInterface)
3. An application has reported as being unhealthy. The worker process will now request a recycle. Reason given: ASP.NET application initialization failed.. The data is the error.
Upvotes: 2
Views: 1212
Reputation: 844
This issue was resolved inside ServiceStack and released as v4.0.17.
Information on the issue from Demis:
It was due to resolving an IDisposable dependency during initialization (i.e. not at runtime) which means the HttpContext.Items doesn't exist so disposables were being tracked in the CallContext's LogicalData store, which apparently in an IIS Express host doesn't support non-serializable items. So I've added a new Container.Exists api to check for IOC existence so we no longer have to resolve items internally (in ServiceStackHost), we're also not tracking items in RequestContext during App initialization.
Why did this work fine with the MemoryCacheClient and not with the RedisClientManager?
Because there's default logic that if you haven't registered an ICacheClient it will first check to see if you have Redis registered in which case it will register it as an ICacheClient otherwise it will register a MemoryCacheClient instead, code is at: https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/ServiceStackHost.cs#L376
Originally it was resolving the instance to check for existence, now it uses the new Exists method that checks without resolving an instance.
@Demis, thanks for the help!
Upvotes: 1