System.Drawing does not exist? - c#

I'm trying to create a validation image using class library in asp.net, but that is not the question.
Anyway, my question is... well... system.drawing does not exist so I cant use "bitmap".
From similar questions, people tell to add reference. But I already did that, restarted my computer etc. It doesn't work.
What can I do besides adding reference? It doesn't work or am I doing it wrong ?
Here is basically what I did:
Right click to references, which is under solution,
add reference
add system.drawing
But still, it does not appear in intellisense or tells me "it does not exist, try adding reference" when I type it manually.

I suspect that you added the System.Drawing reference to the wrong project. Please verify that the Validator.cs file in the project that has the System.Drawing reference.

You can add referrence 'System.Drawing.dll' to your project.

I had the same issue and solved it, click on the project menu, then Add reference, reference manager will open, then click on the assemblies tab, search for System.Drawing and check it then press ok. it will recognize the package or name space.

I stumbled this error even referencing assembly. After thinking i realised that that error produced after adding a class file which is under 'System' folder which i produced on the project folder. That class has ##.System.## namespace as well under the folder. .Net produced error if you have any custom namespace which contains 'System' keyword. Try changing folder name and namespace if u stumbled as well.

Click on the Project tab and then on Add Referenceā€¦
Then select System.Drawing or whatever you want.

In addition to adding the reference, you will also need to import it using the using statement in the top of your code file:
using System.Drawing;

You should change .NET Framework version to .NET 4.0

I have also encountered the same problem. I found that a console/class library project cannot add a reference to System.Drawing. When I changed to use a Window Form project, I was able to add a Bitmap with a reference to System.Drawing.

The error is because you have not added any user control to your class library project. Add a user control to your class library project, and the error will vanish.

I had same problem. I was trying to add Reference to System.Drawing.dll via System Explorer, but it didn't help me. Finally, I put cursor on the varialbe of type 'Graphics', clicked Ctrl+. or 'Alt+Enter->Refactoring' and select 'using System.Drawing'. I don't understand why and how, but it solved my problem.

Related

References c# visual Studio

I have been working on this project in Visual Studio 2010 using C# a few days before Windows 10 update and it worked fine but now when I try to run the program and it tells me the following :
The type or name of the 'Drawing' namespace does not exist in the
'Tekla.Structures' namespace (missing an assembly reference?)
and the same for Tekla.Structures.Model, Tekla.Structures.Model.Operations ... as you can see in the following image:
What I am doing is removing the references and adding them again and in this way the program recognizes it well, but if I clean the solution and try to generate the solution again, the problem arises again ...
What could be the problem?
It seems that you want to use Tekla reference correctly.
I suggest that you can use NugetPackage.
First, right click->References->choose Manage Nuget packages.
Second, choose the Browse->input 'TeklaOpenAPI' in textbox and choose the first.
Third, click install.
Finally after it has been installed, you will see the following correct using code without warning.
first you remove tekla references, select and right click, then remove
remove reference
after right click on References and add reference
add references
after you need add dll corresponding the version you want execute
select references
pay attention when building the app, it only runs in the version you chose the dlls.

The type or namespace name "WebRequestHandler" could not be found

I am trying to use the Dropbox.API code that is listed here:
https://github.com/dropbox/dropbox-sdk-dotnet/tree/master/dropbox-sdk-dotnet/Examples/SimpleTest
I copied their Program.cs into my Program.cs without making other changes to other files in my solution/project.
I am getting
The type or namespace name "WebRequestHandler" could not be found.
Despite having this using statement:
using System.Net.Http;
The help text says to add an assembly reference, but I don't know what I would add.
I tried moving the using System.Net.Http to both inside and outside the class.
I am new to C# and .Net development so expect this to be a really newbie problem.
Have you included a reference to the System.Net.Http.WebRequest DLL? This is where the WebRequestHandler is found, not in System.Net.Http.
See this article on MSDN.
In short, you can add the reference to System.Net.Http.WebRequest DLL by right clicking on the project and doing Add -> Reference. Expect a popup window to appear and then put a checkmark next to System.Net.Http.WebRequest.
I can confirm this lunacy:) You can pull System.Net.Http via NuGet but not System.Net.Http.WebRequest:) System.Net.Http.WebRequest is to be referenced via "Add Reference".

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?
Make sure that System.Drawing is added to the library's assembly references. By default, for class libraries, no Windows Forms assemblies are added.
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.
In case if a particular .NET reference is not added by default, do that manually:
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.

Class Library Intellisense not showing up after adding the dll to the references

In C#, I made a ClassLibrary that has one Namespace and one Class.
I saved it and build it.
in other Projects, when i use it, I add it to my references by browsing to the .dll location.
But The Problem is that its name is not showing up in the Intellisense.
i.e when I: using ... my dll doesn't show ..
I'm Importing the library to a ConsoleApp.
both of the App and the library target Framework is .NET Framework 4.0
and I made their Assembly Version 4.0.0.0 so they're the exact same.
is there a setting or something that I'm missing ?
how can i make it pop up ?
I'm using VS2010 Professional
Thank you for your help
Maybe this be usefull, I was having a similar issue, I have a Web project, add the reference to a Class Library by selecting the project, but if I made a change on the class library, I canĀ“t see that change on the intellisense of the Web Project, after try many things, I see that in the recently added reference, the value of the option "Local Copy" was set "True", then I change it to false and everething works!
I had a similar issue but in my case it was a property on the class. If you go to the file properties and look for a Build Action. Somehow mine was set to Content it had to be set to Compile.
I am using Visual Studio 2013. I hope this helps someone else.
Is the namespace for your assembly different than the namespace for your currently open project? I've had times when the current project and an assembly share the same namespace path the intellisense can mess up.
In general, Visual Studio is pretty good about intellisense generation, especially for C#. But sometimes there are some interesting conditions regarding ambiguities, and especially mixing project types where it just doesn't quite work.
Placing your content in the same namespace makes me wonder if you've actually fixed the problem (it may just be autocompleting the namespace in the currently loaded project rather than the assembly), but if it allows you to continue working, then go with it!
Right click on project on which you add reference of your dll/project select menu project dependancies and select/MarkCheckBox for reference project/dll. then it will work fine.
If the class library project had its name changed after creation, then intellisense may fail finding it due to directory issues, I believe.
I created my class with the generic "ClassLibrary1" or whatever, and then later changed the default namespace, class name, and project name inside of VS2017. I closed VS2017 and changed the directory name to match my default namespace, and then re-associated the project file in VS2017, and then re-added the reference in my main project file.
All seems to be fixed now.

what namespaces are needed for this piece of code? (c#)

Image Dummy = Image.FromFile("image.png");
Dummy.Save("image.bmp", ImageFormat.Bmp);
what the question says
i have these
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
but i get an error saying that the namespace drawing does not exist in the namespace system :/
Add a reference to System.Drawing
When you use using statements, this lets the compiler know that when you say Image you really mean System.Drawing.Image for example.
However, now the compiler needs to know where System.Drawing is. By default, in Visual Studio, you will probably already reference System, System.Data, and System.Xml.
Now you are writing for System.Drawing. Right-click the project in the project browser, and select "Add reference...". This will present you with a tabbed interface that lets you select one of:
A .NET Reference. Any assembly in the GAC will be listed here. Scroll down and select System.Drawing for example.
COM Reference. For interfacing with non-.NET, yet very Windows components.
Projects. A Visual Studio nicety. Reference a DLL that has not been built yet. Select a project within the same solution. Intellisense before you compile.
Browse (for a file). If a .NET component or other type with exported definitions has already been built, you can reference the DLL from here.
Adding the "using" is only part of the equation. You also have to reference the DLL which contains the code you want to use.
For example, if you write a cool library under the namespace com.shuttleu.awesomelib, I could have the following at the top of my C# file:
using com.shuttleu.awesomelib;
On its own, that won't do me any good, I have to reference the DLL (referred to as an "assembly") in my project. You do that by right-clicking the project and selecting "Add Reference..."
In addition to the using statement, you also need to add the System.Drawing DLL (called an 'assembly') as a reference in your Visual Studio project. To do that, in the Solution Explorer pane usually at the right (if it's not open, go to View --> Solution Explorer), right click References and click Add Reference. In the .NET tab (open by default), scroll down until you see System.Drawing, select it, and click OK. After doing that, System.Drawing should appear under References in the Solution Explorer, and the using statement will now point to the correct DLL, therefore your code will work. :)
"Adding the "using" is only part of the equation. You also have to reference the DLL which contains the code you want to use"
Just curious--why do we have to do both for a console app, while in an VB.Net web app, the text "Imports System.Drawing" is sufficient?

Categories