Take the 2-minute tour ×

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
       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

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?


Here's how I'm registering the IValidator ones:

    private void registerFromAssembly(IWindsorContainer container, Assembly assembly)

Here's how I'm registering the IPresenterResolver service:


I have to remove both of these to get the application to run now.

share|improve this question
As the error says, there's a type parameter count mismatch between the service type and the implementation type. Can you post your registrations? –  Mauricio Scheffer Nov 23 '10 at 0:28
What version are you using –  Krzysztof Kozmic Nov 23 '10 at 5:57
@Krzysztof Kozmic: Castle.Core is, Castle.Windsor is I just tried the latest 2.5.2 and it has the same problem. –  Scott Whitlock Nov 23 '10 at 12:38
@Mauricio Scheffer: I posted the registrations. –  Scott Whitlock Nov 23 '10 at 13:24
add comment

1 Answer

up vote 2 down vote accepted

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:

    private void registerFromAssembly(IWindsorContainer container, 
        Assembly assembly)
                    .Unless(type => type == typeof(FluentValidatorWrapper<>))
                    .Unless(type => type == typeof(PassEverythingValidator<>))

In this case FluentValidatorWrapper is a generic base type I use to build type-specific validators and PassEverythingValidator 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.

share|improve this answer
add comment

Your Answer


