Welcome to AspAdvice Sign in | Join | Help

Web Application Project Conversion Tips

I upgraded a major website (Visual Studio Web Site Project) to a Web Application Project on VS2005 SP1 today.  I ran into three snags that are worth mentioning.  Before I get to those, however, make sure if you’re going to do this conversion yourself that you follow these steps.

1) After conversion, I was getting errors with all of my (formerly) App_Code files.  They had been moved to Old_App_Code by the convert to web project tool, but they were not being built.  I was able to cause compile errors by adding garbage characters to the .cs files, so I thought they were being compiled, but in reality they weren’t.  After some minutes of trying to resolve the issue, I opened up the .csproj file in a text editor and noticed that all of these .cs files were listed in <Content /> tags instead of in <Compile /> tags.  So I reloaded the project and in solution explorer I clicked on the files and changed their Build Action (in the Properties dialog) to Compile from Content.  Problem solved.

2) This got me from having 67 errors (all base page classes not found on my 67 web pages) to about 900 errors, all of which were:

The name 'CardNumberTextBox' does not exist in the current context 

or something similar.  Since I had run the Convert to Web Application tool on the whole project, I had foolishly assumed that it would, in fact, run on the whole project.  However, after some additional investigation I discovered one thing in common with all of the pages that were getting these “does not exist in the current context” errors: they were missing .designer.cs files.  Re-running the Convert to Web Application wizard on these files individually removed their errors, proving that this was the issue.  Re-running it on the whole project seemed to get more, but not all, of the pages.  By combining re-running this tool and re-building (along with adding missing references) I eventually got .designer.cs files for all of my ASPX pages, which resolved this issue.  I think a variety of missing project references caused the initial failure of the project-wide tool.

3) In the course of correcting the issues with #2, I ran into a chicken-and-egg problem.  I had pages that included references to custom controls which were (previously) defined in my App_Code.  Now these controls existed in a folder called /code in my WAP project, but the project hadn’t successfully built yet.  Unfortunately, a bunch of pages that used these custom control could not have their designer file generated because they were getting Unknown server tag: ‘LQ:LQLinkButton’ errors.  Can’t build the project (which has this control) until the designer files are in place.  Can’t generate the designer files until the control is built.

I figured there were two possible solutions to this:
a) Move my controls to their own library.  Probably the best option, but my solution had a bunch of projects in it already, and I’m trying not to exacerbate that problem, so I thought I’d try option b first.
b) Exclude all the pages that use my controls from the project, get it to build, and then re-add them one at a time and re-gen their designer files.

Option b did in fact work for me (although it took a while).  Further complicating my migration was my use of the Profile object, a workaround for which is described in ScottGu’s Migration GuideRick Strahl also has some good notes, and the forums are a good place to look or ask questions, too.

One more note – I also had issues referencing things withing templated controls, such as the PasswordRecovery control.  Previously in the codebehind I could refer to EmailTextBox just fine, but with WAP I can’t, even after adding the .designer.cs file.  The solution is to use Recursive FindControl to do it, like so:

TextBox EmailTextBox = Common.FindControl(this.PasswordRecovery1, "EmailTextBox") as TextBox;

if (EmailTextBox != null)

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

if (EmailTextBox != null)

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

if (EmailTextBox != null)

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

this.PasswordRecovery1, "EmailTextBox") as TextBox;

if (EmailTextBox != null)

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

if (EmailTextBox != null)

{

email = EmailTextBox.Text;

name = Membership.GetUserNameByEmail(email);

}

On the plus side, once the 2–3 hours of conversion effort were completed, the project builds MUCH faster…

Published Tuesday, January 23, 2007 5:15 PM by ssmith
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Web Application Project Conversion Tips

Bless you!

"After some minutes of trying to resolve.." Wow, I wasted a little more time than that :-(

Friday, January 26, 2007 1:38 PM by Rob

# re: Web Application Project Conversion Tips

How do you go about converting an ASp.Net web site to an Web Applciation using VS2005?

THanks,

Santiago

Wednesday, June 06, 2007 2:36 PM by saintperez

# re: Web Application Project Conversion Tips

When building the WebApplication I am getting an error like "The type 'ManageAuditTrail' already contains a definition for 'lnkAllFields'". This error is on the designer.cs page

Monday, June 18, 2007 10:44 AM by Raj

# re: Web Application Project Conversion Tips

OMG! I would have never found that Build Action property.  I was pulling my hair out over this.  You are a GOD!

Tuesday, August 07, 2007 8:36 PM by Mike

# re: Web Application Project Conversion Tips

thanks for the tip! i had the build action problem- seems like they should at least tell us that's the default behavior.

Wednesday, August 15, 2007 9:53 AM by brian

# re: Web Application Project Conversion Tips

Hey,

Just spent hours with one page that wouldn't convert over to a web application file.  I was just getting a message that read something like "an exception of type system.exception was generated", most frustrating!

The solution in the end for me was that up at the top of the page my ajax prefix was set to "asp" and my controls had the prefix "ajax".

Rembmer to drag in an ajax control from the tool box and it'll create the page directive up the top

Thursday, January 24, 2008 6:22 AM by Adam

# re: Web Application Project Conversion Tips

Thanks, you saved my day! Just spent half an hour wrestling with a web application project. Then I decided to Google a little and I was instantly directed to your page :)

Monday, March 03, 2008 3:39 PM by Henrik

# re: Web Application Project Conversion Tips

Thanks, you saved me hours.

Thursday, May 29, 2008 5:21 AM by Anthony

# re: Web Application Project Conversion Tips

Spent ages trying to sort all this out until I found this post. Thanks a million.

Tuesday, August 05, 2008 6:09 AM by Nick

# re: Web Application Project Conversion Tips

I am also having this problem with referencing items in templated controls.  I'd hate to have to convert all these to findcontrol calls.  I take it you haven't found another way?  Sigh...

Thursday, November 20, 2008 11:55 PM by Howard

# re: Web Application Project Conversion Tips

Incredible. 2 years after this post, it continue being useful.

"b) Exclude all the pages that use my controls from the project, get it to build, and then re-add them one at a time and re-gen their designer files."

I was losing my mind because the conversion problem, and your solution solved it.

THANKS A LOT!

Saturday, March 07, 2009 8:08 PM by André Figueiredo

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below