C# and Visual Studio "Gotchas"
Michael A. Covington
Institute for Artificial Intelligence
The University of Georgia
Athens, Georgia
Last revised 2003 September 16
Contents: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 goofinessNote: 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.Summary:
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 does not do much when you tell it to update itself on the Web. You will miss updates if you rely on this. Use Windows Update, and see also the following notes.
- You may need to install both .NET Framework 1.0 and 1.1 on your computer. Version 1.1 does not replace 1.0.
- If they're installed, you should keep updating them both.
- Users of Visual Studio .NET (2002, not 2003) need Service Pack 2 for .NET 1.0, available from Microsoft here This includes Service Pack 1.
Note: I currently distrust this. A major problem (see below) may have come in with it. Since I had no problems with earlier versions, I am not presently using this update.
- Users of Visual Studio .NET 2003 will need to update .NET 1.1 as updates become available.
- It is widely disputed whether Visual Studio .NET 2002 or 2003 is more reliable. The newer version should be better.
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.
THE REST OF THIS DOCUMENT IS ABOUT C# PROGRAMMING FOR .NET.
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:
- After editing the .ico file, you must select it again in Form Design, Properties. The reason is that Visual Studio does not actually use the .ico file at compile time. Instead it copies the .ico file into the .resx file that it generates (e.g., Form1.resx) and uses that copy of it.
- When you edit the .ico file, note that it really has two icons in it, one of them 32x32 and the other 16x16. You're probably editing the 32x32 icon but seeing the 16x16 icon. In Visual Studio, when editing an .ico file, be sure to look at both images. Choose Image, Current Icon Image Types.
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.
![]()
|
nor are they endorsed by, the University of Georgia or the University System of Georgia. |