【发布时间】:2012-09-13 16:05:27
【问题描述】:
我有这段代码(简化版)
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);
}
}
}
但指示的行 (CreateInstanceAndUnwrap) 失败并显示
程序集“Castle.Windsor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc”中的类型“Castle.MicroKernel.Lifestyle.Scoped.CallContextLifetimeScope”未标记为可序列化。
这是为什么?我确实在应用程序中使用 Castle Windsor,但没有尝试在应用程序域之间传递 CallContextLifetimeScope 实例。
【问题讨论】:
-
我在尝试运行涉及 Castle Windsor 3.0 的 mspec 集成测试时遇到了同样的错误。我正在使用 BeginScope()。我根本没有使用任何 AppDomain 的东西(我怀疑 mspec 可能是)。奇怪的是,R# Mspec 跑步者很好。
-
@AlanChristensen,ReSharper 运行程序不会为每个测试程序集设置新的 AppDomain。你能解决问题吗?
标签: .net castle-windsor appdomain