There are many situations where you are building a solution that contains custom user controls and custom forms that other classes are dependent on. In a project that I'm currently working on we have this need as well. I have created a User Control, this control is kind of like the Visual Studio toolbox. This control is in a project that a few projects have a dependency on. In the main form this control is placed onto the form using the VS Designer. Sometimes when I need to change how the main form looks like, I get the following error.
*************************************************************************************************
|
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes. |
| |
|
**************************************************************************************************************************
I knew that all the code for the main form and its dependencies were OK because, I had viewed the form recently & everything builds fine. I ran into this problem a while ago when I was writing forms using Managed C++ with VS 2003. I assumed that the problem had been resolved, since I haven't run into it while using VS 2005 & C#, but seems like I was wrong.
I did a search and found that there are a few work items at the MSDN Product Feedback Center, in particular there is this item which is closely related. Based on some of the workarounds there and some other information that I have found it seems like the soultion is to
- Close all open files in Visual Studio
- Close Visual Studio
- Delete all temporary files
- Rebuild solution
- Open form
Doing all of this is a hassel, but better then not being able to visually design your forms! To reduce the pain of this process I have created an MSBuild file which will find and delete all the file located under every bin and obj folder. If your solution contains a different OutputPath which is not under the bin folder, or a folder other than obj for the BaseIntermediateOutputPath, then you'll need to edit this file. Also if for some reason you have files under these directories that you do not want to delete then please don't use this file because that would just be sily.
You can download the file form the link at the bottom of this page (DeleteTempFiles.proj). We will discuss its content and how to use it now. The file content is shownn below.
<
Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CleanFiles"><ItemGroup>
<FilesToDelete Include="**\bin\**\*;**\obj\**\*"/>
ItemGroup>
<Target Name="CleanFiles" DependsOnTargets="ShowFiles">
<Delete Files="@(FilesToDelete)" ContinueOnError="true" />
Target>
<Target Name="ShowFiles">
<Message Text="Files%0d%0a:@(FilesToDelete,'%0d%0a')"/>
Target> Project>
There are two targets in this file, the CleanFiles target and the ShowFiles target. As you might expect the CleanFiles target deletes all of those files and the ShowFiles target simply prints a list of all the files that will be deleted. You can use this to help determine if you should execute the CleanFiles target. You should place this file in a folder at the top of the solution heirarchy. If you have projects in different locations other then under the same path then you'll have to modify the FilesToDelete declaration to pick those up as well. Before you run this file you should close all open files in Visual Studio and then exit out of Visual Studio. Following this open the Visual Studio Command Prompt, navigate to the folder which has the DeleteTempFiles.proj file. To show which files will be deleted you can do:
>msbuild.exe DeleteTempFiles.proj /t:ShowFiles
To delete these files:
>msbuild.exe DeleteTempFiles.proj /t:CleanFiles
Following this open Visual Studio, rebuild the solution and then open the form in the designer. If all goes well you should see your form again!
This saves me some time. I get this problem in VS 2005 many times a day. I find it incredible that Microsoft has not fixed this in some way. This has got to be the single worst bug in VS.
Comments are closed.