Question

(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:

  1. Create a new ASP.NET Webforms Application in VS 2013.
  2. Update Nuget Packages
  3. Install Nuget Package => Install-Package ServiceStack.Host.AspNet
  4. Run App - Example todo's work. /metadata shows example services
  5. Startup a local or remote instance of Redis (I tested both local on Windows, remote on Linux)
  6. Add the RedisClientsManager to the AppHost.cs

container.Register(c => new PooledRedisClientManager("localhost:6379")); container.Register(c => (ICacheClient)c.Resolve() .GetCacheClient()) .ReusedWithin(Funq.ReuseScope.None);

  1. Run the project, you should just get a blank screen in Chrome
  2. Navigate to /metadata and you will get a generic HTTP Error 500.0 - Internal Server Error
  3. 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.

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top