BUG: You cannot add a user control to a Windows Form in Visual Studio .NET 2003

Article translations Article translations
Article ID: 825007 - View products that this article applies to.
Expand all | Collapse all

On This Page

SUMMARY

You may experience problems when you try to add a user control to a Windows Form, or when you open a Windows Form that has a user control. This article describes the behavior that you may experience. It also describes the cause of this behavior and how you can work around it.

This article includes the steps to reproduce the behavior and links to references that contain more information about the SerializationException class, assemblies, how to configure Folder Redirection and roaming user profiles, and how to use the .NET Framework Configuration tool to configure code groups.

SYMPTOMS

In Microsoft Visual Studio .NET 2003, you may be not be able to add a user control from the Toolbox to a Microsoft Windows Form. Additionally, when you open a Windows Form that contains a user control, or when you try to build a project that has a Windows Form that contains a user control, the user control may disappear. When this problem occurs, you may receive the following error messages in the Task List window:
The variable VariableName is either undeclared or never assigned.


Could not find Type Namespace.UserControlName. Please make sure the assembly that contains this type is referenced. If this is part of your development project make sure that it is properly built.
A System.Runtime.Serialization.SerializationException exception error may also occur. The exception error message contains the following text:
Insufficient state to deserialize the object. More information is needed.
Note These error message examples use the following placeholders:
  • VariableName is a placeholder for the name of the user control variable.
  • Namespace is a placeholder for the name of the namespace that contains the user control class.
  • UserControlName is a placeholder for the name of the user control class.
Also, you may notice the error messages after you upgrade a Microsoft Visual Basic 6.0 project to Microsoft Visual Basic .NET 2003. And, this problem does not occur in Microsoft Visual Studio .NET 2002.

CAUSE

Visual Studio .NET 2003 creates temporary files for project-level assemblies such as the assembly that contains the user control. These temporary files are located in the %APPDATA%\Microsoft\VisualStudio\7.1\ProjectAssemblies folder. Visual Studio .NET 2003 then loads the assemblies from the temporary files into memory. If you use folder redirection to redirect your Application Data folder to a folder that is not fully trusted, such as a network shared folder, Visual Studio .NET 2003 cannot load the assembly.

Typically, the problem that is mentioned in the "Symptoms" section occurs if you are using a roaming user profile.

WORKAROUND

Fully trust all files that are located in the ProjectAssemblies folder. To do this, follow these steps on your local computer:
  1. Start the Microsoft .NET Framework 1.1 Configuration tool. The .NET Configuration 1.1 window opens.
  2. In the left pane of the .NET Configuration 1.1 window, expand Runtime Security Policy, and then expand Machine.
  3. Expand Code Groups, and then expand All_Code.
  4. Right-click LocalIntranet_Zone, and then click New. The Create Code Group dialog box appears.
  5. Click to select the Create a new code group option.
  6. In the Name box, type MyCodeGroup, and then click Next.
  7. In the Choose the condition type for this code group box, click URL.
  8. To fully trust all files that are located in the ProjectAssemblies folder, type the following text in the URL box:
    file:////FolderPath\Microsoft\VisualStudio\7.1\ProjectAssemblies\*
    Note FolderPath is a placeholder for the path of the folder that you redirected the Application Data folder to.
  9. Click Next.
  10. In the Use existing permission set box, click FullTrust, and then click Next.
  11. Click Finish.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Visual Studio .NET 2002 directly loads project-level assemblies into memory without using a temporary file. Therefore, the behavior that is mentioned in the "Symptoms" section does not occur in Visual Studio .NET 2002.

Steps to reproduce the problem

Note Follow these steps after you redirect your Application Data folder to a folder that is not fully trusted.
  1. Start Visual Studio .NET 2003.
  2. Use Visual Basic .NET to create a Windows Control Library project. By default, a project that is named WindowsControlLibrary1 and a file that is named UserControl1.vb are created.
  3. Build the Windows Control Library project to create the WindowsControlLibrary1.dll assembly.
  4. On the Tools menu, click Add/Remove Toolbox Items. The Customize Toolbox dialog box appears.
  5. Click the .NET Framework Components tab.
  6. On the .NET Framework Components tab, click Browse. The Open dialog box appears.
  7. Locate and then click the WindowsControlLibrary1.dll assembly that you created in step 3.
  8. Click Open, and then click OK. The UserControl1 user control is added to the Toolbox.
  9. Use Visual Basic .NET to add a Windows Application project to your solution. By default, a Windows Form that is named Form1 is created.
  10. Try to add a UserControl1 user control to the Form1 Windows Form. You cannot add the user control.
  11. Open a project that has a Windows Form that contains a user control, such as a Microsoft Visual Basic 6.0 project that you upgraded to Visual Basic .NET 2003.
  12. Open the design view of the Windows Form. The user control may disappear. Also, in the Task List window, you may notice the first two error messages that are mentioned in the "Symptoms" section.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
SerializationException class
http://msdn2.microsoft.com/en-us/library/system.runtime.serialization.serializationexception(vs.71).aspx

Assemblies
http://msdn2.microsoft.com/en-us/library/hk5f40ct(vs.71).aspx

Configuring Folder Redirection
http://technet2.microsoft.com/windowsserver/en/library/CAD7966E-C9B6-495F-B7BB-2A9673F69F4F1033.mspx

Roaming user profiles
http://msdn2.microsoft.com/en-us/library/aa374409.aspx

Configuring code groups using the .NET Framework Configuration tool
http://msdn2.microsoft.com/en-us/library/eb8xw74a(vs.71).aspx

Properties

Article ID: 825007 - Last Review: May 18, 2007 - Revision: 3.4
APPLIES TO
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Academic Edition
Keywords: 
kbvs2005swept kbvs2005doesnotapply kbdesigner kbpolicy kbmisctools kbsyssettings kbtrusts kbprofiles kbsecurity kbuser kbupgrade kbbug kberrmsg kbwindowsforms KB825007

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com