C# and Visual Studio "Gotchas"

Michael A. Covington
Institute for Artificial Intelligence
The University of Georgia
Athens, Georgia

Last revised 2003 September 16

Versions and updates of .NET and Visual Studio
Can I still develop Win32 (non-.NET) programs???
Visual Studio hangs when you're editing C or C++ code
Badly deformed GUI - buttons missing
Changing the icon of a form has no effect!
The project location is not fully trusted...
Unhandled exception of type System.Resources.MissingManifestResourceException...
Miscellaneous goofiness

Note: Click here for a good tutorial on the C# language, aimed at people who know some C++ or Java.

What is a "gotcha"?

"Gotcha" ("got you") is what a practical joker exclaims when revealing that he has tricked you. In software, a "gotcha" is an unexpected and unexplained problem that is hard to troubleshoot -- a dirty trick played by the software.

The following "gotchas" are things I encountered while doing C and C# programming with Visual Studio 1.0 (2002). For the most part, they are not otherwise well documented on the Web, which is why I created this page.

Versions and Updates of .NET and Visual Studio

The situation with versions of .NET and Visual Studio is confusing.


Explanation: In .NET, every application is bound to the DLLs that it was compiled with. It will not use a newer DLL unless that DLL is tagged as a later release of the same version. This is to prevent "DLL Hell," the strange situation where updating a DLL will often break a conventional (non-.NET) program.

Visual Studio .NET (2002) and programs compiled with it use .NET Framework 1.0.

Visual Studio .NET 2003 and programs compiled with it use .NET Framework 1.1.

Can I still develop Win32 (non-.NET) programs???

Yes! Visual Studio provides a C and C++ compiler that works just like the previous Visual C++ compiler and generates .exe files that don't require .NET Framework. Choose "C/C++ Console," "Win32 Project," or one of the "MFC" options if you want to use it. If you want to use C or C++ to write a program for .NET, choose "Managed C++".

Visual Studio hangs when you're editing C or C++ code

This is a known problem and a patch is available from Microsoft. See here for details.

Quick fix:

On the Tools menu, click Options.

In the left pane, expand the Text Editor and the C/C++ nodes.

Click Formatting, and then click to clear the Enable automatic Quick Info ToolTips check box.

(Quick fix is quoted from Microsoft.)

Badly deformed GUI - buttons missing

This one has to be seen to be believed. The IDE starts up, but many of the buttons are missing, and there are some strange-looking windows left open in front of everything:

It turned up when we tried to use Visual Studio .NET with roaming user profiles on our network, and it also affected some users with local accounts. Although I'm not sure I've really diagnosed the problem, it has to do with file permissions. (Note that, when running, Visual Studio has to write in your user profile, and also in C:\Documents and Settings\All Users, no matter who is using it.)

Here are steps that seem to clear up the problem (thorough tests have not been made):

(1) Make sure "Everyone" has "Full Control" of C: (i.e., the root of the local hard disk). (There is probably something less extensive than this that you can do to fix the problem, but I havenít pinned it down.)

(2) As is our usual practice, run mscorcfg.msc (in \Windows\Microsoft.NET, under version 1.0) and make sure Local Intranet is set to Full Trust.

(3) On the local machine, add the group "Users", as a group, to the group "Debugger Users."

(4) Any user who has ever had the problem must delete

%USERPROFILE%\Application Data\Microsoft\Visual Studio

which contains corrupt information. Otherwise, once the GUI problem has hit you, it will stay with you forever. If there is a Visual Studio folder in Local Settings\Application Data\Microsoft (and Iím not sure there ever will be), delete that too.

(5) Avoid the service pack for .NET Framework 1.0. I think the problem may have come in with it.


Changing the icon of a form has no effect!

If you specify no icon for a form, you get an icon containing some little colored boxes. Alternatively, you can select the file App.ico, which looks like a tiny window.

You can create more .ico files and/or edit App.ico with Visual Studio. But when you do, the changes seem to have no effect! There are 2 tricks to it:

Where is the icon for the application (the .exe file)?

Right-click on the whole project in Solution Explorer, and choose Properties. It's data loaded from an .ico file, and the preceding remarks apply to it.

"Unhandled exception of type System.Resources.MissingManifestResourceException."

Let me guess: You have a .cs file that defines a form, but you have put another class definition into the same file, preceding the class that defines the form.

This is perfectly legal C# syntax, but it confuses the compiler terribly.

It makes the compiler generate a .resources file with the wrong name. This typically breaks the program only if the form has an icon or a background image.

The cure? Put each class in a different file. (Project, New, Class will do this for you.) Or at least, put each form in a .cs file by itself, and then put your classes which are not forms in one or more additional .cs file.

I should add that the .resources file is not needed to run your program.  It is in the obj directory, and its contents are placed in the .exe file.

"The project location is not fully trusted."

Problem: A user is unable to develop programs with Visual Studio .NET, getting the error message "The project location is not fully trusted." This typically happens when using a network drive or a roaming user environment.

It may also happen when running a compiled .NET program.

Solution: The computer needs to be told that network drives are safe places on which to run .NET code.

Log in as administrator on the affected PC.

Open C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\mscorcfg.msc (location may vary slightly).

Right click on Runtime Security Policy.

Choose "Adjust Security."

Set Local Intranet to FullTrust.

Miscellaneous goofiness

Make sure you are using current versions of Visual Studio and .NET.

The content and opinions expressed on this Web page do not necessarily reflect the views of,
nor are they endorsed by, the University of Georgia or the University System of Georgia.