AppDomain.CreateInstanceAndUnwrap 失败并显示“类型未标记为可序列化”
我有这段代码(简化)
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 实例。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此问题现已在 Windsor 3.1 中修复。
当跨 AppDomain 使用范围生活方式时,就会发生这种情况。一些测试运行程序(如 MsTest)或其他库(如 Reporting Services)正在另一个应用程序域中执行某些操作,这就是您看到此情况的原因。
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.