Click here to Skip to main content
14,694,375 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I've got a program from other coworker. I would like to add a debugging message by calling MessageBox.Show(). That's the reason I must add one line of "using System.Windows.Forms;" in the beginning of the file. I got error of
"The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)"
What's wrong with it? I used "using System.Windows.Forms;" very well at another file of the same project and copy that line from other file. What does "assembly reference" mean? What should I do to work it out?
Posted
Updated 20-Apr-20 15:15pm
v2
Comments
   
I'll never get it: why trying to program anything without reading on the very basics?
—SA
   
Web application? where!?
—SA
Stan Huang 17-Jul-15 2:48am
   
No, it's not a web application, but a Windows application's class library.
   
All right, thank you for the confirmation. Perhaps "Web application" was nothing but the fantasy by Arkadeep De.
—SA

This is because you don't have a clue what "using" does, just not yet. You cannot do any development at all without understanding assemblies and their reference. You develop one or more assemblies, and one can be used by another one. You can do it be referencing one assembly by another one, or by dynamically loading another assembly and using reflection to access its types and their members. Dynamic loading is related to advanced techniques, but referencing is the basis of all technology, making it impossible to do anything at all without referencing.

Referencing in Visual Studio is done by "Add Reference" in Solution Explorer. For understanding of referencing, you can start here: https://msdn.microsoft.com/en-us/library/8wxf689z%28v=vs.110%29.aspx[^].

You also need to understand what a modules, and different kinds of reference, importantly, GAC and signing, and, hence, the idea open-key cryptography. Please, find it all by yourself before asking further question.

As the "using" directive (not to be mixed up with "using" statement), they merely help to shorten the names of the assembly-level type names. You are not obliged to use "using" at all, can just use full type names in all cases. This is nothing but syntactic sugar. You just need to understand namespaces: https://msdn.microsoft.com/en-us/library/0d941h9d.aspx[^].

—SA a**hole
   
v2
Comments
Stan Huang 17-Jul-15 2:46am
   
I reached it by right clicking on that project on Solution Explorer and then 'Add Reference' --> 'Assemblies' --> Framework, then checked the 'System.Windows.Forms'.
   
No, it's Solution Explorer, Project node/References node, Add Reference -> Add Reference window, .NET tab. Then you can use System.Windows.Forms namespace as well.
—SA
Suvendu Shekhar Giri 17-Jul-15 4:16am
   
5*. Perfectly described and the correct answer.
   
Thank you, Suvendu.
—SA
First of all, are you sure it's a windows form application ? I suspect it to be a WPF application.

You need to add reference to System.Windows.Forms.
To do that go to the Solution Explorer and right click on the project and click on Add Reference and then select System.Windows.Forms.

Hope, it helps :)
   
Comments
   
(Sigh...) I'm really sorry, but there are no signs of WPF application so far. First of all, nothing prevents using System.Windows.Forms in WPF assembly, and visa versa. Nothing at all. There could be a lot of reasons why some assembly is not referenced. One can start with console application and start adding Forms stuff without knowing that the assembly should be added. Another one could have removed the reference by whatever reason.

The root of the problem is: our inquirer has no clue of assemblies and references. This is the root, and nothing else.

Even though your advice to "Add Reference" is quite valid, the whole post appears way too confusing to the beginner, and apparently our inquirer is the absolute beginner.

Thank you for understanding.

—SA
Suvendu Shekhar Giri 17-Jul-15 4:13am
   
I agree. Sorry for my assumptions. First of all, I should have asked OP about the application type before posting an answer.
Secondly, I'll try to be more descriptive in future for questions like these so that inquirers can get the root cause rather making them more confused or clue-less.

Thanks @SA :)
Sergey Alexandrovich Kryukov 17-Jul-15 10:59am
   
I really appreciate your understanding and consideration.
—SA
Stan Huang 17-Jul-15 2:42am
   
It's a Class Library, built in VS2012.
   
All right, you can well reference System.Windows.Forms in it, and use your forms in some application referencing your library...
—SA
You have to complete the References of your Project (Project-Settings - I don't know how it is called in your Installation of VS) with the necessary assemblies.

In your case you need to integrate the assembly "System.Windows.Forms"
   
v2
Comments
   
I'm really sorry, not in none of the Visual Studio versions with .NET it's "Project settings". It's "Solution Explorer". Also "integrate the assembly" is wrong term. I hate to say that, but it's better not to confuse the beginners. Please understand: how can it help anyone?
—SA
Ralf Meier 17-Jul-15 2:40am
   
Sorry - as I have written : I don't know how it is called in other languages - my VS is installed in German ...
But what I not understand ... where is the mistake - in this case the inquirer needs to add the reference (because I think it's missing) - see also the Suggestion in solution 2 - it points to the same ...

But if you think that your solution is more helpful to the inquirer ...
   
I just mean that the references to IDE actions are very confusing. The problem is: there is really Project => Properties, but there is no adding reference there for C# projects, but there is for C++/CLI. Imagine the confusion of the beginner sent to the dead end... :-)
—SA
Stan Huang 17-Jul-15 3:00am
   
Yes, I do find "Add Reference" under "Project" for VC# project.
Ralf Meier 17-Jul-15 3:24am
   
Thanks for your reply ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900