无法实例化 Windsor 自定义组件激活器

发布于 2024-09-04 23:32:08 字数 424 浏览 4 评论 0原文

我在调用 Resolve 时遇到异常:

KernelException: Could not instantiate custom activator
Inner Exception:
{"Constructor on type 'MyProj.MyAdapter`1[[MyProj.MyBusinessObject, MyAsm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' not found."}

那里肯定有一个公共无参数构造函数(并且我已经在运行时使用反射验证了这一点)...所以我认为问题可能与它是通用的这一事实有关?我尝试获取组件模型对象并将 RequiresGenericArguments 设置为 true,但这并没有让我有任何进展。

任何帮助将不胜感激!谢谢。

I'm getting an exception calling Resolve:

KernelException: Could not instantiate custom activator
Inner Exception:
{"Constructor on type 'MyProj.MyAdapter`1[[MyProj.MyBusinessObject, MyAsm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' not found."}

There's definitely a public parameterless constructor there (and I've verified this using reflection at runtime)...so I figure the problem might have to do with the fact that it's generic? I've tried getting the component model object and setting RequiresGenericArguments to true, but that hasn't gotten me anywhere.

Any help would be much appreciated! Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼性发作 2024-09-11 23:32:08

Windsor 不使用默认构造函数来实例化激活器。

新版本抛出了更有用的异常消息:

Castle.MicroKernel.KernelException : Could not instantiate custom activator
  ----> System.ArgumentException : Type Castle.Windsor.Tests.ActivatorWithoutCorrectConstructor does not have a public constructor matching arguments of the following types:
Castle.Core.ComponentModel
Castle.MicroKernel.DefaultKernel
Castle.MicroKernel.ComponentInstanceDelegate
Castle.MicroKernel.ComponentInstanceDelegate

所以你需要一个像这样的构造函数

public YourActivator(ComponentModel model, IKernel kernel,
                                    ComponentInstanceDelegate onCreation,
                                    ComponentInstanceDelegate onDestruction)

Windsor is not using default constructor to instantiate activators.

The new version throws a more helpful exception message:

Castle.MicroKernel.KernelException : Could not instantiate custom activator
  ----> System.ArgumentException : Type Castle.Windsor.Tests.ActivatorWithoutCorrectConstructor does not have a public constructor matching arguments of the following types:
Castle.Core.ComponentModel
Castle.MicroKernel.DefaultKernel
Castle.MicroKernel.ComponentInstanceDelegate
Castle.MicroKernel.ComponentInstanceDelegate

So you need a constructor like this

public YourActivator(ComponentModel model, IKernel kernel,
                                    ComponentInstanceDelegate onCreation,
                                    ComponentInstanceDelegate onDestruction)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文