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.