Click here to Skip to main content
15,860,972 members
Articles / Web Development / ASP.NET
Tip/Trick

Regenerate aspx.designer.cs Files When Corrupted

Rate me:
Please Sign up or sign in to vote.
4.78/5 (5 votes)
26 Jun 2014CPOL3 min read 38K   5   2
This post explains how you can regenerate the designer.cs and designer.vb files when they are corrupted, missing or giving compile errors.

Introduction

This post explains how you can regenerate the designer.cs and designer.vb files when they are corrupted, missing or giving compile errors. Occasionally it happens that you receive compile errors in your *.aspx.designer.cs or *.aspx.designer.vb files in your project and it seems that there’s virtually nothing you can do. Some seem to be caused by Visual Studio bugs, others are caused by wrong usage or copy and pasting pages from outside your project. Be as it may, often these issues are deceptively easy to solve! Here’s a step-by-step solution.

Step 1: Open Your Project Web Application vs Web Site

Open Your Project

Your project must be a Web Application project. If you have a Web Site project, you do no need to worry about designer.cs files, because they won’t be there: a Web Site does not need any, it’s the cleaner and more advanced version of a Web Application.

If you are in doubt, check the picture on the right.

Step 2: Delete the designer.cs File

Open Your Project

When you delete the designer.cs file, the file must be listed like in the picture by Step 1. Right-click the file in the Solution Explorer and select the Delete option. Do not delete the file from disk using the normal Windows Explorer, or Command prompt or whatever. If you did so, you must still right-click the item (now with a warning symbol) and select Delete. Deleting the file is a harmless action, the file does not contain any valuable information and you should have never edited it yourself, because it would be overridden by Visual Studio when auto-generating it again. All it contains are the declarations of the protected fields, which are declared in the ASPX file declaratively.

Step 3: Convert to Web Application

Open Your Project

Convert to Web Application only if you removed the designer.cs file as described in Step 2, you will find this option when you right-click the project or the ASPX file. After you click this menu option, the designer.cs file will be regenerated for you. Perhaps a better word for this menu option could’ve been: repair designer.cs. In which case they should have made it available at any time, to force-regenerate the designer.cs. Perhaps in Visual Studio 2010?

Remarks

If nothing happens, you may have tried to delete the *.aspx.designer.cs file from Windows Explorer or a Command Window. Don’t do that: you must remove it from inside the Visual Studio environment or this trick will not work at all. If you deleted the file externally, you can still follow the three steps above, as Visual Studio will still show the referenced designer.cs file as a missing file in your Solution Explorer.

Compatibility

This tip works and is tested with the following versions of Visual Studio:

  • Visual Studio 2005
  • Visual Studio 2008
  • Visual Studio 2010

Credit

Credit for this tip go to Matthias Suter for briefly pointing to this possibility on his blog.

History

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Pakistan Pakistan
Director Operations e Best Solutions. With 14 years of experience in the IT industry, I have multi-dimensional skills in different technologies. I started as a Web Developer/Designer (asp classic, PHP) but the majority of My career was spent in conquering expertise in Microsoft .NET + MS SQL + N-tier architecture design & development. I hold a Bachelor Degree in Computer Science, Karachi University, Pakistan. Love to work hard. Have a good understanding in writing complex stored procedure and database design.

Comments and Discussions

 
QuestionDo not attempt in VS 2012 or 2013 Pin
DavidHungerford6-Jan-15 7:43
DavidHungerford6-Jan-15 7:43 
AnswerRe: Do not attempt in VS 2012 or 2013 Pin
DanXiong1-Jul-15 11:23
professionalDanXiong1-Jul-15 11:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.