views:

384

answers:

3

I have an ASP.NET web application project which references another project called ModusCore (or Modus.Core). We've had a variety of controls that use ModusCore up until now with no problem, but there's one I created lately that's been causing trouble. Here's the code:

public class PortalLinkNew : WebControl
{
    public string Text { get; set; }
    public bool AllowPush { get; set; }

    public PortalLinkNew()
    {
        AllowPush = true;
    }

    public IChannelRequest ChannelRequest { get; set; }

    protected override HtmlTextWriterTag TagKey
    {
        get { return HtmlTextWriterTag.A; }
    }

    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {
        try
        {
            base.AddAttributesToRender(writer);
            if (DesignMode || Page == null || !(Page is IPortalPage))
            {
                return;
            }
            string href = "/";
            if (ChannelRequest != null)
            {
                var portalPage = (IPortalPage)Page;
                href = portalPage.Module.PortalRouter.GetLinkUrl(portalPage, ChannelRequest, AllowPush);
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Href, href);
        }
        catch (Exception)
        {

        }
    }

    public override void RenderEndTag(HtmlTextWriter writer)
    {
        writer.Write(Text);
        base.RenderEndTag(writer);
    }
}

In the above code, IPortalPage and IChannelRequest are interfaces defined in Modus.Core.

My intent is to use this control in my code as follows:

<tnl:PortalLinkNew ID="CancelButton" runat="server" Text="Cancel" OnInit="CancelButton_Init" />

This actually compiles and runs without a problem, but when I'm editing the page (source view) in Visual Studio 2008, I get the following warning:

Generation of designer file failed: Could not load file or assembly 'Modus.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

As it says, it doesn't regenerate the designer file, meaning any attempt to refer to the CancelButton control in code-behind results in a compiler error. Following advice I've found online, I've tried deleting the corresponding .ascx.designer.cs file and using "Convert to Web Application" on that page, but it tells me that it cannot rebuild the designer file for the same reason mentioned above.

I've tried everything I can think of: cleaning the solution, restarting Visual Studio, rebooting my computer, deleting the code directory and pulling it fresh from the repository, removing and re-adding the project and dll references, etc. The same problem occurs on multiple computers I use.

How can I get the VS designer to stop failing?

+2  A: 

I have a very similar problem (which I could not solve yet). The Application I have the problem with was converted from a "Web Site Project" though and I can't get rid of the feeling that this has something to do with it. And I am on VS 2005.

Now what I can add is that

a) "sometimes" (I could not figure out when exactly yet) the "Convert to Web Application"-trick works for me (but not always)

b) "sometimes" (same as above) it helps to switch to the designer view, change something and save -> *.designer.cs gets regenerated

I usually try several things in no fix order after I added a control to my page until "something" works.

There is a lot of noise about this on the internet but I could not find a "real fix" for it (yet). One thing I read besides the already mentioned is that it could have something to do with (not matching/not existing) namespaces.

When I checked my application there really were no namespace declarartions in the *.cs-files. So I added them (in *.cs and *.aspx) and for some time thought it did the trick. But sadly by now I know that this was not the case...

scherand
+1 option (b) worked for me
roufamatic
+2  A: 

I've been struggling with this problem all day, and you wouldn't believe what the culprit was. I disabled ReSharper 5.0 and all of a sudden the errors went away. Unbelievable.

chaiwalla
Hmmm, the plot thickens.
StriplingWarrior
+1 describes my situation, too... add a little more cornstarch to that plot.
roufamatic
Try opening the .designer.cs file and deleting all of it's contents. Close it and then modify your webform/control again - it should be regenerated. It worked for me.
wows
A: 

Adding a third option for when @scherand's (a) and (b) fail:

c) "Sometimes", this works as well:

  • Remove the <%@ Register... %> entries
  • Save the .AS?X file. Let the designer complain.
  • Add the <%@ Register... %> again
  • Save again

[Added Oct-13-2010]:
d) "Sometimes", as well:

  • Clear the AS?X file off all but the most basic content.
  • Start adding pieces back, one bit a time.
  • Save.
  • Check that you didn't get the error message.
  • Add back a few more pieces. Rinse. Repeat.

I use a text comparison tool against a back up copy of the AS?X file for this.

I try to avoid adding the controls that cause the error until the very end. I also try to add from the bottom of the page. However, I don't know of a hard rule. It's a gut-feeling exercise.

(Will someone ever figure this one out?)

Euro Micelli