Invalid type owner for DynamicMethod

Topics: Web Client Software Factory, UIP Application Block discussion
Apr 4, 2009 at 1:07 PM
Hello

I have a WCF application that was throwing an exception, "Invalid type owner for DynamicMethod". I have read through other discussions regarding this issue but they didn't illuminate the solution for me. In the composition of this post, I discovered the problem and fixed it, but I have a lingering doubt about the fix and I hope that someone will be able to clarify what's going on.

I have just one business module, the default Shell module, but several foundation modules. The content of my pages is largely created dynamically from a database, and I have a module called Content that takes care of this for me. I pass a reference to a <asp:Panel> object on my page to the presenter, then to the controller, which finally passes it to the Content module which does the actual work of assembling the content and inserting it into the panel.

In the process of creating the content in this way, the Content module inserts either Literal text objects or, in the case that it finds special markup that I have created in my content, it instantiates various user controls and inserts them appropriately. This was all working great - until this morning.

I have several controls, some derived from System.Web.UI.UserControl, and some, which require services, derived from Microsoft.Practices.CompositeWeb.Web.UI.UserControl. For example, I have an EmailSubscribe control which is an example of the second of these, because this control needs to interact with the database. This control works fine, no problems.

However, today I created another control derived from the CompositeWeb control, and it is when inserting this control into the panel object that the exception was thrown. This control is called ContentLink. All of these controls are in the same module, the Shell module.

I stripped down the implementation code for the ContentLink control, which fails, so that it matches the EmailSubscribe code, and discovered that it was when trying to instantiate the presenter for my ContentLink that the exception was throw, so I turned my attention to the presenter.

I discovered that, whereas the EmailSubscibe control presenter has a dependency on the Shell module, which then calls the Content module, the ContentLink presenter bypasses the Shell and interacts directly with the Content module. I did this simply because the ConentLink was merely passing the same parameters through four methods until it finally reached the Content module.

So; why can't the ContentLink presenter have a direct dependency on the Content module, whereas the Shell can, even though the ContentLink presenter and the Shell are in the same module?

Sorry for the long-winded explanation....

Regards, Mark