bookthief
bookthief

Reputation: 2451

namespace not working in class library c#

I am trying to create a class library using some classes that I created in another project. One of the classes uses images and needs the System.Drawing namespace. However, when I try to copy the code from my project into a new class in my class library, I get an error saying the image object does not exist in the current context, and

The type or namespace name "Drawing" does not exist in the namespace System(are you missing a using directive or an assembly reference?)

It works fine in the other class as part of the other project. Why would this be?

Upvotes: 3

Views: 5677

Answers (4)

Vasanth
Vasanth

Reputation: 81

using System.Drawing; 

Write this in top of your class file. then also if u get error right click on reference and add reference of System.Drawing in your project.

Upvotes: -1

KMC
KMC

Reputation: 20046

In case if a particular .NET reference is not added by default, do that manually:

screenshot

Upvotes: 0

KING
KING

Reputation: 980

Yes The problem lies in the References. If you go to your Solution Explorer and expand it, you will see a nested Folder Titled 'References'. Here is where you add the references needed in your project. To add them, simply right click the folder and select add Reference. Once here the reference you need will be in the .Net tab.

Upvotes: 1

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56697

Make sure that System.Drawing is added to the library's assembly references. By default, for class libraries, no Windows Forms assemblies are added.

Upvotes: 12

Related Questions