- | rssFeed | My book on MSBuild and Team Build | Archives and Categories Monday, 16 January 2006

WinForms Designer Load Error

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.


Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Hide    


at System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark)
at System.Reflection.Assembly.GetTypes()
at Microsoft.VisualStudio.Shell.Design.AssemblyObsoleteEventArgs..ctor(Assembly assembly)
at Microsoft.VisualStudio.Design.VSDynamicTypeService.ReloadAssemblyIfChanged(String codeBase)
at Microsoft.VisualStudio.Design.VSDynamicTypeService.CreateDynamicAssembly(String codeBase)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.Search(String fullName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, String description)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchProjectEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.GetType(ITypeResolutionService trs, String name, Dictionary`2 names)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.FillStatementTable(IDesignerSerializationManager manager, IDictionary table, Dictionary`2 names, CodeStatementCollection statements, String className)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)

**************************************************************************************************************************

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

  1. Close all open files in Visual Studio
  2. Close Visual Studio
  3. Delete all temporary files
  4. Rebuild solution
  5. 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!

DeleteTempFiles.proj (.43 KB)
msbuild | Visual Studio Monday, 16 January 2006 05:46:42 (GMT Standard Time, UTC+00:00)  #     |  Tracked by:
"robots airport code" (air online) [Trackback]
"california poker room" (casino online) [Trackback]
"buy cheap phentermine online pharmacy" (best online pharmacy diet phentermine p... [Trackback]
"carisoprodol soma" (drug soma) [Trackback]
"celexa online rx drugs" (celexa use and weight gain) [Trackback]
"overseas discount pharmacy vardenafil" (vardenafil hcl vision duration) [Trackback]
"adipex p" (adipex) [Trackback]