I'm new to C#. However, this seems like a trivial problem that yet I cannot find an answer to.
I'm trying to simply return a Bitmap object (defined via an interface) yet it cannot "find" the Bitmap class. I've imported the appropriate namespace System.Drawing; and yet I'm still getting the same error,
Type or namespace reference cannot be found (are you missing an assembly reference?)
Here is the code presently:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace ConsoleApplication1
{
public interface PlanetInterface
{
bool isColonized();
bool isDestroyed();
Bitmap getImage(); //Why does Bitmap not 'exist'.
}
}
Any help is much appreciated. Thanks.
You need to add Reference to System.Drawing it is not referenced by default in Console application:
Related
Okay so essentially this is happening:
I am trying to run a
Thread tcpHandlerThread = new ParamaterizedThreadStart(tcpHandler);
but I get the error
the type or namespace ParamaterizedThreadStart does not exist
on ParamaterizedThreadStart but I have these imports:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
Sorry if this is a stupid question :\ What imports am I missing or is it just an error with my Visual Studio?
ParameterizedThreadStart is a delegate.
use this instead..
Thread tcpHandlerThread = new Thread(tcpHandler);
If you want to run methods with parameters. you can use this..
Thread tcpHandlerThread = new Thread(() => tcpHandler(parameters));
It looks like you misspelled the ParameterizedThreadStart class.
The link below might help you and has a good example how to create a parameterized thread.
https://msdn.microsoft.com/en-us/library/1h2f2459%28v=vs.110%29.aspx
I decided to try working with C# over c++ but ran into a problem.
The following code snippet shows the problem.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Device;
namespace Project_AREA
{
public partial class Form1 : Form
{
private Device device;
public Form1()
{
InitializeComponent();
}
}
}
That's as much code as I have right now.
In private Device device;, the keyword Device is not getting recognized although all the libraries have been referenced and the using directives are included.
Any ideas?
Managed to Solve the problem.. for your reference and also if other run in to the same problem. You must add all the following references to the project: (note all files can be found on your had disk at c:\Windows\Microsoft.NET\DirectX for Managed Code) 1: Microsoft.DirectX.dll from folder 1.0.2902.0 2: Microsoft.DirectX.Direct3D.dll from folder 1.0.2902.0 3: MicrosoftMicrosoft.DirectX.Direct3DX.dll from folder 1.0.2911.0 Thanks for the help tho guys :)
i have this structure:
Entity:(It's a Project named "Entity" - type: ClassLib)
Class 1;
Class 2;
Class 3;
DataBase:(It's a Project named "DataBase" - Type: ClassLib)
Class 1;
Class 2;
Class 3;
MainProject: (Windows Form)
Some Forms;
Then what I did was:
Added both projects into MainProject's references
Wrote on the codebehind:
using DataBase;
Worked perfect... But when I try to add the DataBase Project into the codebehind, it doesn't show up while I'm typing and also give me this error:
Error 2 The type or namespace name 'DataBase' could not be found (are you missing a using directive or an assembly reference?)
Ps: All the Classes of the projects (Class 1,2,3...) have the same namespaces wich is the project's name.
I tried some stuff I found on the internet, but nothing worked... Any Idea why?
UPDATE
My Code:
MainProject
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Entity; ( WORKED ! I can acess Entity's Class)
using DataBase; <---------------------------------- (ERROR HERE)
I am trying to write an extension method for the WPF Window class. I am doing it in a class library project in my solution, so that I can use it in all my projects in the solution.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace ExtensionMethods
{
public static class MyExtensions
{
public static void ResizeToPrimaryScreenWorkingArea(this System.Windows.Window w)
{
}
}
}
When I try to compile this, I get the following error:
The type or namespace name 'Window' does not exist in the namespace
'System.Windows'
Yes, I DID add references to System.Windows and System.Windows.Forms in my class library project, and they are showing under References in the project in Solution Explorer.
What am I doing wrong?
Add PresentationFramework.dll reference to your project it contains the System.Windows namespace.
http://msdn.microsoft.com/es-es/library/system.windows.window(v=vs.110).aspx
I have the following code but still have to type full path to use the System.IO.Ports namespace even though I have the using clause in place. Am I missing something in my reference list?
The = new SerialPort returns a Error 5 'SerialPort' is a 'namespace' but is used like a 'type'
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace SerialPort
{
public partial class Form1 : Form
{
System.IO.Ports.SerialPort counter = new SerialPort("COM5");
public Form1()
{
InitializeComponent();
}
Thanks
You're declaring a namespace of SerialPort. Don't do that. That's what's causing the problem.
All you've got to do is change the namespace, and you'll be fine. You could use an alias as per Honza's request, but I think the code would be clearer to everyone if you just renamed the namespace.
It's because your namespace carries the same name. Either rename your namespace or use an alias for the serial port, like this:
using SP = System.IO.Ports.SerialPort
And then you can use
SP counter = new SP("COM5");
But as Jon suggested, renaming your namespace is a clearer solution to anyone who'll read your code.