3
votes

I have this code (simplified)

internal class Worker : MarshalByRefObject {
    public void DoWork() {
    }
}

internal class WorkerInvoker {
    public void InvokeWorker() {
        var newDomain = AppDomain.CreateDomain("Work", null, new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, PrivateBinPath = AppDomain.CurrentDomain.RelativeSearchPath });
        try {
FAIL HERE>  var worker = (Worker)newDomain.CreateInstanceAndUnwrap(typeof(Worker).Assembly.FullName, typeof(Worker).FullName);
            worker.DoWork();
        }
        finally {
            if (newDomain != null)
                AppDomain.Unload(newDomain);
        }
    }
}

but the indicated line (CreateInstanceAndUnwrap) fails with

Type 'Castle.MicroKernel.Lifestyle.Scoped.CallContextLifetimeScope' in assembly 'Castle.Windsor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' is not marked as serializable.

Why is this? I do use Castle Windsor in the application, but am not trying to pass a CallContextLifetimeScope instance between app domains.

1
I have this same error trying to run mspec integration tests with Castle Windsor 3.0 involved. I am using BeginScope(). I am not using any AppDomain stuff at all (I suspect mspec may be). Strangely the R# Mspec runner is fine.Alan Christensen
@AlanChristensen, the ReSharper runner does not set up a new AppDomain per test assembly. Were you able to solve the problem?Alexander Groß

1 Answers

2
votes

This issue is now fixed in Windsor 3.1.

It happens when scoped lifestyle is used across AppDomains. Some test runners (like MsTest) or other libraries (like Reporting Services) are doing some stuff in another app domain and that's why you're seeing this.