castleproject/Windsor

Missing MethodException when using UsingFactoryMethod

awigglesworth opened this issue · 3 comments

Hi There,

We are in the process of updating our Castle versions to the latest (upgrading from version 3.4). We found that when we run the code, we get a MissingMethod Exception thrown when registering a container.

Here's the code snippet:

    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Install(
            new CommonCliDependencyInstaller()
        );

        container.Register(
            Component.For<IOperationContextResolver>().ImplementedBy<RealTimeOperationContextResolver>(),
            Component.For<ChangeExclusionScope>().LifestylePerThread(),
            Component.For<IncludeOperationalFieldsScope>().LifestylePerThread(),
            Component.For<ChangeTrackerScopeInterceptor>().LifestyleTransient(),
            Component.For<RealTimeChangeSetOperationContext>().LifestylePerThread(),
            Component.For<IHPDBFieldClassificationCache>().ImplementedBy<HPDBFieldClassificationCache>(),
            Component.For<IChangeTracker>().ImplementedBy<ChangeTracker>(),
            Component.For<IProgramRunner>().ImplementedBy<ProgramRunner>(),
            Component.For<IWindsorContainer>().UsingFactoryMethod(() => container)
        );

        RegisterDataComponents(container);

        RegisterRules(container);

        RegisterCommands(container);
    }

Here is the result:

System.MissingMethodException : Method not found: 'Castle.MicroKernel.Registration.ComponentRegistration`1<!0> Castle.MicroKernel.Registration.ComponentRegistration`1.UsingFactoryMethod(System.Converter`2<Castle.MicroKernel.IKernel,!!0>, Boolean)'.

Sounds like you haven't recompiled against the newer version of Windsor. The method signature of UsingFactoryMethod changed in v4.0:

-public ComponentRegistration<TService> UsingFactoryMethod<TImpl>(Converter<IKernel, TImpl> factoryMethod, bool managedExternally = false)
+public ComponentRegistration<TService> UsingFactoryMethod<TImpl>(Func<IKernel, TImpl> factoryMethod, bool managedExternally = false)

It's definitely compiled against the latest version. We don't have compile problems, just at run time when executing our unit tests.

You can close this problem, it was caused by a reference in one of our dependent projects not being updated. Thanks for the hint jonorossi!