what namespaces are needed for this piece of code? (c#) - 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?

Related

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".

C# using others code

Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right hand side -> Download.
However I can't open the whole project on my Microsoft Visual C# 2010 Express (that also runs C# XNA) because
Solution folders are not supported in this version of the application
Also I just want the class to use separately in my own seprate project.
I tried to copy the three important seeming files Interval.cs, IntervalNode.cs and IntervalTree.cs into my project but this generated the compile error
There are no importers which handle this file type
I've also tried to copy and paste the contents of the three files into my project, encapsulating them into there own namespace as well as there was a lot of code. I had to rearange some of the usings a little but have run into the problem that possibly it wants PowerCollections .dll and .pcb files as using Wintellect.PowerCollections; causes
The type or namespace name 'Wintellect' could not be found (are you missing a using directive or an assembly reference?)
I'm not sure how to continue or if I'm doing the right thing at all in how to get this class to work.
Add the library to your solution
Copy the IntervalTreeLib directory into your solution directory. Then, right-click your solution, and add existing project. Point it at IntervalTreeLib.csproj in IntervalTreeLib, and click Open. That should add the IntervalTreeLib project to your solution.
Add a reference to the library in your project
Then, in your project, add a reference to the IntervalTreeLib proejct:
- Right click the References folder, and Add Reference. Click the Projects tab, and select IntervalTreeLib.
Use the classes in your code
To use classes from the library in your source then, you need to either add:
using IntervalTreeLib;
void Foo() {
IntervalTree<int, int> tree = new ...
}
Or, refer to them by their full name:
IntervalTreeLib.IntervalTree<int, int> tree = new ...
Open the IntervalTreeLib.csproj file if you want to be able to open the project in it's entirety (or in your current solution add an existing project (you can right-click on the solution) and select the IntervalTreeLib.csproj). If you are trying to grab just the code file in your project, ensure you also grab the PowerCollections.dll file (I see it is in the same folder as the code files) or your code will not compile (as you have discovered). You'll need to add a reference to it and include the needed using statement at the top of the code files making use of this library (or use fully qualified name with the namespace).
using IntervalTreeLib;
or
var myObj = new IntervalTreeLib.[WhateverClass](...);
Also, make sure you read the license.txt file. You may need to include it if you are using the code. Give credit where it is due.
UPDATE:
If the test project is causing you problems, just open the library project. Ideally you could just open that and compile it, adding the output DLL files that are generated directly into your solution. This is ideal unless you are planning on changing the library source code itself.
Add the library to the references of the project you want to use it.
Since discussing that you are able to build Intervallib.dll, we will discuss about how you should the dll in your project.
Now in your proj, right click on the references part and add the dll intervallib.dll to your references. In your game.cs file, have the reference to the namespace as -- using IntervalTreeLib;
then you should actually copy the dll powercollections.dll to the bin directory of proj directory also.
you should copy this dll because there is an indirect link to the dll as it is used in IntervalTreeLib.dll
following these steps, I was able to execute this project.

System.Drawing does not exist?

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.

Use .dll files in winforms

I have a .dll file.I want to add this file to my program and use the component of its.(in C# & winforms)
How do I can do this?
Thanks.
Right click your WinForms project and say Add Reference, then browse to the DLL.
I tend to put any third-party DLLs in a folder called "Dependencies" inside my solution so that they are all kept together. It also makes it easier to move the solution around.
Add it as a reference to your project and then provide a using in any source file where you want to import the namespace to use the types within the DLL.
You should first put the .dll in your application folder. If there is an accompanying xml file, put that in there too. The XML file is the detailed comments so when you work with the .dll it will have explanations for things.
Right click on your project in solution explorer and choose add a reference. Choose the dll thats in your project.
If the dll is name Company.Description.dll, put a using command at the top of your code:
`using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Company.Description;`
You should be able to see what the dll has added by typing in Company.desciption. hit control + space bar. The intellisense should show you what that dll contains.
Add reference from Solution Explorer (Remember you can add only managed code DLLs)
or
if using windows form you can also add control to Toolbox
Right Click on Toolbox ->Choose Items... ->Browse for your dll

I can't add a using reference on my C# application

I'm using Visual Studio 2010 Beta2 and I can't add a reference to:
system.drawing
I've tried right click on the solution explorer but I can't find it there.
What gives?
Here is all you need to do in VS 2010:
In Solution Explorer right click on the References folder of your project
Select Add Reference.
Under the Assemblies category there is a sub category of Framework. If that is selected you should see a list of all of the Microsoft .NET Framework libraries
Find System.Drawing and double click it.
Then your project will have the reference added to it!
In VS2010 Beta 2 the references list may not be automatically sorted because it loads asynchronously. You may need to wait for it to finish loading then click the column header to sort.
Solution explorer is for adding references to external libraries.
It sounds like you just want to add the line
using System.Drawing;
to the top of one particular file.

Categories