3
Vote

Invalid type owner for DynamicMethod.

description

I have a module UserInformation and in the website of this module i have added one usercontrol login.ascx. Now i have placed the user control in the homepage of the website, and have called a method from presenter object. this method's logic is in Userinformationservice class so now i am getting this error please suggest what to look for.

comments

egarcia74 wrote Oct 27, 2009 at 7:17 AM

We came accross this problem in our application and we came up with a solution.

In our case, the user control had its own presenter which also used interacted with a controller defined in the same module as the presenter. The issue was that when controllers are registered in the module Load method, they are registered only in the module's container - not globally. This means that the controller can only be instantiated if the DI container being used is from the same module.

To overcome the problem, we simply changed the module initializer's Load method to register the controller on the parent container (same as for global services).

I.e. change the following code...

    public override void Load(CompositionContainer container)
    {
        base.Load(container);

        AddGlobalServices(container.Parent.Services);
        AddModuleServices(container.Services);

        ...

        container.RegisterTypeMapping<IAdministrationController, AdministrationController>();
    }

... into this:

    public override void Load(CompositionContainer container)
    {
        base.Load(container);

        AddGlobalServices(container.Parent.Services);
        AddModuleServices(container.Services);

        ...

        // Register the controller on container.Parent to make it available for DI globally.
        container.Parent.RegisterTypeMapping<IAdministrationController, AdministrationController>();
    }

royhiggs wrote Nov 16, 2009 at 6:51 PM

Many, many thanks for this response. Helped me out tremendously.

Jensch wrote Jun 23, 2010 at 9:36 AM

Thank you, this helped me solve the issue in no time.