Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# Nicole 7/10/2006 6:05 PM
As a means of learning the module system, I'm attempting to create a really simple module by following the module development instructions. However, I keep getting the following error and stack trace:
 Unable to cast object of type 'ASP.modules_imagecontrol_web_imagecontrol_ascx' to type 'Cuyahoga.Web.UI.BaseModuleControl'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'ASP.modules_imagecontrol_web_imagecontrol_ascx' to type 'Cuyahoga.Web.UI.BaseModuleControl'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Unable to cast object of type 'ASP.modules_imagecontrol_web_imagecontrol_ascx' to type 'Cuyahoga.Web.UI.BaseModuleControl'.]
   Cuyahoga.Web.UI.PageEngine.LoadModuleControl(ModuleBase module) in X:\WWWROOT\cuya\Web\UI\PageEngine.cs:325
   Cuyahoga.Web.UI.PageEngine.CreateModuleControlForSection(Section section) in X:\WWWROOT\cuya\Web\UI\PageEngine.cs:317
   Cuyahoga.Web.UI.PageEngine.LoadContent() in X:\WWWROOT\cuya\Web\UI\PageEngine.cs:285
   Cuyahoga.Web.UI.PageEngine.OnInit(EventArgs e) in X:\WWWROOT\cuya\Web\UI\PageEngine.cs:225
   System.Web.UI.Control.InitRecursive(Control namingContainer) +321
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +692

Any ideas? I have a very simple "Hello World" control, module code-behind, and module controller. Could there be a problem with my codebehind file not being recognized properly?
# sandaru1 7/10/2006 11:25 PM

You need to inherit the module code behind class from the BaseModuleControl class.

Regards,

Sandaruwan
# mgaerber 7/11/2006 2:49 AM
Hi,
I also had this problem, even when inheriting from BaseModuleControl. Surprisingly, it worked after I de-installed and installed my custom module again.
# Nicole 7/11/2006 12:37 PM
As outlined in the module development document, my codebehind class inherits BaseModuleControl and my module controller class inherits ModuleBase.

Perhaps the module development document is out of date?

(mgaerber -- I'm going to try your approach right now.)
# Nicole 7/11/2006 1:42 PM (edited 7/11/2006 1:45 PM)
I tried mgaerber's approach to no avail. I've even tried removing it completely from the project, readding it, and rebuilding. What am I missing here?

Addendum: Also, I'm using .NET 2.0 -- could that be an issue?
# Nicole 7/11/2006 5:51 PM
I was finally able to make this work by adding
Inherits="Cuyahoga.Web.UI.BaseModuleControl"

to the @Control tag of the .ascx file. Of course, while this works, it also tells me something isn't quite right. I think it has to do with the .NET 2.0 web user control model. I added a simple Label web control to my user control assigned text to it from my codebehind and...nothing. This made me think the new 2.0 model isn't playing nice with the old codebehind file. Digging around, I found that the "Codebehind" attribute is no longer used in favor of the "Codefile" attribute. Updating that and the Inherits attribute (as required to fix another error), throws me a nice fat namespace error. Hopefully I can reconcile the current module development model with the new .NET user control model (and preferably before I go insane).
# mgaerber 7/12/2006 1:41 AM
Actually, you are right. My control was empty and now that I added a gridview, nothing get's rendered, not even the "EmptyDataTemplate".

Did you choose WebApplication as project type for the module? I guess this is some fundamental problem of mixing the .NET 1.0 page engine and .NET 2.0 web controls.

As soon as I have a solution for this, I will post it here...
# Nicole 7/12/2006 3:37 PM (edited 7/12/2006 3:39 PM)
So, after more research, I found that I was somewhat misinformed regarding CodeFile vs. CodeBehind. CodeBehind is still available. However, using CodeBehind still doesn't fix my problem. I tried a Button control instead to no success. The button shows up, but the text applied to it from the codebehind file does not.

My .ascx file:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ImageControl2.ascx.cs" Inherits="Cuyahoga.Modules.ImageControl2.ImageControl2" %>
<asp:Button ID="_plh" runat="server" />

The codebehind:
namespace Cuyahoga.Modules.ImageControl2
{
    public partial class ImageControl2 : BaseModuleControl 
    {
        private ImageControl2Module _module;
        protected System.Web.UI.WebControls.Button _plh;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //add stuff here
            this._module = this.Module as ImageControl2Module;

            _plh = new System.Web.UI.WebControls.Button();
            _plh.Text = "my text.";
        }
    }
}

(I thought the 2.0 model didn't require redeclaration of web controls, but my code wouldn't compile without it.)

Anyone who can tell me what's going on will be my hero.

[Edit:] Oh, and mgaerber, my module is set up as a web application project.
# mgaerber 7/13/2006 1:42 PM
this is how it works for me:

CompanyList.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CompanyList.ascx.cs" Inherits="Cuyahoga.Modules.AxxCompany.Web.CompanyList" %>

CompanyList.ascx.cs :
...
namespace Cuyahoga.Modules.AxxCompany.Web
{
    public partial class CompanyList : BaseModuleControl
    {
...

CompanyList.ascx.designer.cs :
namespace Cuyahoga.Modules.AxxCompany.Web {
    
    public partial class CompanyList {
        protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
    }
# mgaerber 7/13/2006 1:45 PM
by the way, if you want to use the MikroKernel to access components you have to do it explicitly in the codebehind:
using Castle.MicroKernel;

namespace Cuyahoga.Modules.AxxCompany.Web
{
    public partial class CompanyList : BaseModuleControl
    {

        private ICompanyService cs;

        protected void Page_Load(object sender, EventArgs e)
        {
            IKernel kernel = ((AxxCompanyModule)this.Module).kernel;
            this.cs = (ICompanyService)kernel[typeof(ICompanyService)];


in the module controller, I am registering my service components as follows:
namespace Cuyahoga.Modules.AxxCompany
{
    class AxxCompanyModule : ModuleBase, INHibernateModule, ISearchable
    {

        public IKernel kernel;

        public AxxCompanyModule(IKernel kernel)
		{
            this.kernel = kernel;
		}

        #region Overrides

        public override void RegisterComponents()
        {
            kernel.AddComponent("AxxCompany.CompanyDao", typeof(ICompanyDao), typeof(CompanyDao));
            kernel.AddComponent("AxxCompany.CompanyService", typeof(ICompanyService), typeof(CompanyService));
        }

        #endregion
# Nicole 7/13/2006 2:35 PM
mgaerber, you get to be my hero!

I didn't realize that control declarations need to be in the designer.cs partial class. I never use the built in drag-drop interface as I generally like to handcode stuff, but because of this, the designer.cs file wasn't getting updated. So, I deleted my control, used the designer to add a Label and, sure enough, it showed up in the designer.cs file and now works.

I wish it wasn't so touchy, but at least it works now. I can finally move forward.

Thanks!