• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Simple C# Error?

limecat

Weaksauce
Joined
Jul 15, 2004
Messages
101
I have the following very short bit of code that I've written in VS 2005 Express:

Code:
 using System;
 using System.Windows.Forms;
 
 namespace Tutorials.UsingAForm
 {
 	public class AForm : Form
 	{
 		static void Main()
 		{
 			System.Console.WriteLine("Wheee");
 		}
 	}
 }

When I try to run it, i get the following error:

error CS0012: The type 'System.ComponentModel.IComponent' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Anyone know what I'm doing wrong? Google hasn't been very helpful, and I'm new to VS so deciphering this one is proving tricky.
 
Haven't run into this error before (99% of my C# code is web stuff) - but it's saying you need to reference an assembly your trying to use - Right click on the references folder on the Solution window, select Add Reference, and go thru the list of assemblies - you probably need at a miniumum, System and System.Windows.Forms. - A google search turns up this: http://msdn2.microsoft.com/en-us/library/system.componentmodel.icomponent.aspx - you need a reference to the System.dll

Anytime I work in VS (especially 2005) if the intellisense isn't working right, then I KNOW I've screwed something up (usually a reference or a using statement)..

Hope this helps.
 
Bohica69 said:
Haven't run into this error before (99% of my C# code is web stuff) - but it's saying you need to reference an assembly your trying to use - Right click on the references folder on the Solution window, select Add Reference, and go thru the list of assemblies - you probably need at a miniumum, System and System.Windows.Forms. - A google search turns up this: http://msdn2.microsoft.com/en-us/library/system.componentmodel.icomponent.aspx - you need a reference to the System.dll

Anytime I work in VS (especially 2005) if the intellisense isn't working right, then I KNOW I've screwed something up (usually a reference or a using statement)..

Hope this helps.
Yeah that fixed it. I had System.Windows.Forms but not System. I added that one in and everything works now. Thanks! =)

BTW, since I'm new to C#, what do these References do, anyways? Are they libraries like C++ <include>s?
 
Since I haven't done any C+ coding, I'm not 100% certain ;)

But a quick google search makes me beleive they are the same (or very similar). Basically references in C# are so the compiler knows what dll's need to link in during compilation.
 
Yup, references tell the compiler what to bind the code against.

The using statements just import namespaces, but a given namespace can span multiple libraries, or there can be multiple alternate implementations of a given namespace.
 
Back
Top