System.drawing namespace not found under console application
Asked Answered
N

8

68

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.

Nowhither answered 18/12, 2011 at 16:38 Comment(1)
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.Becalmed
T
-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

Transistorize answered 18/12, 2011 at 16:46 Comment(3)
Wrong. System.Drawing.dll is in the Client Profile.Dumb
but this method got rid of those error messages. Will this method lead to bad application behavior down the road ?Nowhither
This does not work for me -- I had to add the reference to System.Drawing as blueshift says.Theoretical
D
218

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

Dumb answered 18/12, 2011 at 16:39 Comment(10)
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?)Nowhither
Then you didn't properly add the reference.Dumb
this is what i did -> using System.Drawing.dll;Nowhither
No; you need to add a reference. Right-click on the project.Dumb
@Nowhither 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.Messapian
This should be the accepted answer. Importing the dll is the proper solution.Apomixis
@Dumb I cannot find System.Drawing anywhere I am creating a UWP appApplicable
@KristjanKica: You need to use UWP APIs.Dumb
incase of missing System.Drawing reference or missing latest version, install it using PM command. ->Install-Package System.Drawing.Primitives -Version 4.0.0Shroud
@Nowhither 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 !Proximal
A
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.
Ayrshire answered 18/12, 2011 at 16:51 Comment(0)
A
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
Amenable answered 8/12, 2016 at 8:0 Comment(0)
F
9

Install this library from Nuget

System.Drawing.Common

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

Franni answered 8/12, 2021 at 6:13 Comment(0)
P
7

Install-Package System.Drawing.Common

Prussiate answered 10/8, 2020 at 13:14 Comment(0)
A
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;

Allier answered 30/7, 2013 at 19:13 Comment(0)
H
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

Hadwyn answered 15/8, 2017 at 1:39 Comment(0)
T
-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

Transistorize answered 18/12, 2011 at 16:46 Comment(3)
Wrong. System.Drawing.dll is in the Client Profile.Dumb
but this method got rid of those error messages. Will this method lead to bad application behavior down the road ?Nowhither
This does not work for me -- I had to add the reference to System.Drawing as blueshift says.Theoretical

© 2022 - 2024 — McMap. All rights reserved.