65

I selected console application as my C# project. But the imports that seemed to work under Windows Form project don't seem to work here. It says that the drawing namespace does not exist.

using System.Drawing;
using System.Drawing.Imaging;

My problem is that I need to have the bitmap class. I am trying to make a command line app that does bitmap manipulations to a image. That's why I didn't choose my project to be a Windows Form one.

Null
  • 1,950
  • 9
  • 30
  • 33
klijo
  • 15,761
  • 8
  • 34
  • 49
  • 2
    You need to be aware that references and namespace imports are two separate concepts. A single assembly may contain types in multiple namespaces. A single namespace may contain types from multiple assemblies. `using` statements (being namespace oriented) aren't a mechanism for adding assembly references. – Damien_The_Unbeliever Dec 18 '11 at 16:45

8 Answers8

216

You need to add a reference to System.Drawing.dll.

As mentioned in the comments below this can be done as follows: In your Solution Explorer (Where all the files are shown with your project), right click the "References" folder and find System.Drawing on the .NET Tab.

enter image description here

enter image description here

MindRoasterMir
  • 324
  • 1
  • 2
  • 18
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    no it does not work. Still i get The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?) – klijo Dec 18 '11 at 16:42
  • Then you didn't properly add the reference. – SLaks Dec 18 '11 at 16:44
  • this is what i did -> using System.Drawing.dll; – klijo Dec 18 '11 at 16:45
  • 11
    No; you need to add a **reference**. Right-click on the project. – SLaks Dec 18 '11 at 16:46
  • 2
    @klijo That's just a using declaration. In your Solution Explorer (Where all the files are shown with your project), right click the "References" folder and find System.Drawing on the .NET Tab. – vcsjones Dec 18 '11 at 16:46
  • 2
    This should be the accepted answer. Importing the dll is the proper solution. – Ondrej Sotolar Oct 01 '14 at 09:55
  • @SLaks I cannot find System.Drawing anywhere I am creating a UWP app – kkica Jun 20 '18 at 13:57
  • 2
    @KristjanKica: You need to use UWP APIs. – SLaks Jun 20 '18 at 14:25
  • incase of missing System.Drawing reference or missing latest version, install it using PM command. ->Install-Package System.Drawing.Primitives -Version 4.0.0 – jay sedani Jun 25 '21 at 11:18
  • @klijo Be aware to choose the right console app for your project! On Visual Studio Community 2022 I mistakenly chose "Console Application" tagged with _C#, Linux, macOS, Windows, Console_ . For full support of System.Drawing you need to choose "Console App (.NET Framework)" tagged with _C#, Windows, Console_ ! – SourceSeeker Mar 09 '22 at 22:04
10
  1. Add using System.Drawing;
  2. Go to solution explorer and right click on references and select add reference
  3. Click on assemblies on the left
  4. search for system.drawing
  5. check system.drawing
  6. Click OK
  7. Done
WhiteWolfza
  • 225
  • 3
  • 7
10

If you are using Visual Studio 2010 or plus then check the target framework that is it .Net Framework 4.0 or .Net Framework 4.0 Client Profile. then change is to .Net Framework 4.0.

You need to add reference this .dll file (System.Drawing.dll) to perform drawing operations.

If it is OK then follow these steps to add reference to System.Drawing.dll

  1. In Solution Explorer, right-click on the project node and click Add Reference.
  2. In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
  3. Select the System.Drawing.dll to reference, then click OK.
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
7

Install-Package System.Drawing.Common

7

Install this library from Nuget

System.Drawing.Common

https://www.nuget.org/packages/System.Drawing.Common/6.0.0

5

For,Adding System.Drawing Follow some steps: Firstly, right click on the solution and click on add Reference. Secondly, Select the .NET Folder. And then double click on the Using.System.Drawing;

user2635504
  • 51
  • 1
  • 1
2

Add reference .dll file to project. Right, Click on Project reference folder --> click on Add Reference -->.Net tab you will find System.Drawing --> click on ok this will add a reference to System.Drawing

Niraj Trivedi
  • 2,370
  • 22
  • 24
-12
  1. Right click on properties of Console Application.
  2. Check Target framework
  3. If it is .Net framework 4.0 Client Profile then change it to .Net Framework 4.0

It works now

Jerther
  • 5,558
  • 8
  • 40
  • 59
dotnetstep
  • 17,065
  • 5
  • 54
  • 72