Castle Windsor ResolveAll 因类型参数异常而失败
我正在使用温莎城堡进行 IoC。它一直工作得很好,但是每次我尝试运行我的应用程序时,它都会在 ResolveAll
调用期间失败:
var resolved = container.ResolveAll<IValidator>();
它会抛出此异常:
System.ArgumentException occurred
Message=The number of generic arguments provided doesn't equal the arity of the generic type definition.
Parameter name: instantiation
Source=mscorlib
ParamName=instantiation
StackTrace:
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at Castle.MicroKernel.Handlers.DefaultGenericHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired) in c:\TeamCity\buildAgent\work\1ab5e0b25b145b19\src\Castle.Windsor\MicroKernel\Handlers\DefaultGenericHandler.cs:line 51
InnerException:
真正奇怪的是,它一直工作得很好,直到今天。如果我回滚到开始执行此操作之前的版本,即使回滚到上周,我仍然会收到此错误。我尝试过重新启动等。以前有人见过这个吗?
编辑:
这是我注册 IValidator 服务的方式:
private void registerFromAssembly(IWindsorContainer container, Assembly assembly)
{
container.Register(
AllTypes.FromAssembly(assembly)
.BasedOn<IValidator>()
);
}
这是我注册 IPresenterResolver 服务的方式:
container.Register(
Component.For<IPresenterResolver>()
.ImplementedBy<CommandLineArgumentPresenterResolver>()
);
我必须删除这两个服务才能让应用程序立即运行。
I'm using Castle Windsor for IoC. It's been working great, but all of a sudden every time I try to run my application, it fails during a ResolveAll
call:
var resolved = container.ResolveAll<IValidator>();
It throws this exception:
System.ArgumentException occurred
Message=The number of generic arguments provided doesn't equal the arity of the generic type definition.
Parameter name: instantiation
Source=mscorlib
ParamName=instantiation
StackTrace:
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at Castle.MicroKernel.Handlers.DefaultGenericHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired) in c:\TeamCity\buildAgent\work\1ab5e0b25b145b19\src\Castle.Windsor\MicroKernel\Handlers\DefaultGenericHandler.cs:line 51
InnerException:
The really odd thing is that it's been working great up until today. If I roll back to a version before it started doing this, even back to last week, I still get this error. I've tried rebooting, etc. Has anyone seen this before?
EDIT:
Here's how I'm registering the IValidator ones:
private void registerFromAssembly(IWindsorContainer container, Assembly assembly)
{
container.Register(
AllTypes.FromAssembly(assembly)
.BasedOn<IValidator>()
);
}
Here's how I'm registering the IPresenterResolver service:
container.Register(
Component.For<IPresenterResolver>()
.ImplementedBy<CommandLineArgumentPresenterResolver>()
);
I have to remove both of these to get the application to run now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须下载温莎城堡源代码,以便我可以在故障源处对其进行调试。事实证明,我错误地包含了一些通用基本类型服务,而我只期望非通用具体实现。我必须将我的注册代码更改为此才能使其工作:
在本例中,
FluentValidatorWrapper
是我用来构建特定于类型的验证器的通用基本类型,而PassEverythingValidator
是一个通用的当我的验证逻辑找不到特定于类型的验证器时手动实例化的类型。这些不应该包含在容器中。我在温莎城堡邮件列表上做了一个注释,如果具体的类型信息已包含在异常中,那么调试起来会更容易。
I had to download the Castle Windsor source code so I could debug it at the source of the failure. It turns out that I was incorrectly including some generic base type services where I was only expecting non-generic concrete implementations. I had to change my registration code to this to make it work:
In this case
FluentValidatorWrapper
is a generic base type I use to build type-specific validators andPassEverythingValidator
is a generic type that my validation logic manually instantiates when it can't find a type-specific validator. These shouldn't have been included in the container.I made a note on the Castle Windsor mailing list that if the concrete type information had been included in the exception, it would have been easier to debug.