Error while trying use project's classes into another project - c#

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)

Related

Bitmap can't be returned?

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:

Creating Device in C# (Device not recognized as keyword)

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 :)

The type or namespace name 'Window' does not exist in the namespace 'System.Windows'

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

CS0234 - Cannot Instantiate C# class in ASP.NET

I made the same ASP.NET C# project in both VS2010 and MonoDevelop using these two classes among the standard files (Site.Master, Web.Config, Default.aspx, etc.) and recieve this same error (CS0234) seen at the bottom.
Login.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using mynamespace;
namespace mynamespace
{
public partial class Logon
{
public void btnClicked(object sender, EventArgs e)
{
//ERROR IS HERE:
mynamespace.Test session = new mynamespace.Test();
//Obviously, this doesn't work either:
Response.Write(session.echoUser());
}
}
}
Test.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using mynamespace;
namespace mynamespace
{
public class Test
{
public string echoUser()
{
return "foobar";
}
}
}
I recieve the same error in both IDEs, here is the MonoDevelop error:
The type or namespace 'Test' does not exist in the namespace 'mynamespace' (are you missing an assembly reference?) (CS0234) Logon.cs
Basically, the class Test refuses to instantiate. Any input is appreciated!
If you have that Test class in an ASP.Net web project, then you need to place it in the App_Code folder, not just anywhere in the site.
You need to refer the projects to each other, if you haven't done so yet. I'm guessing that you don't get the intellisense to show the class in the other namespace, right?
You can see the References on the right side (most cases) under your project view. You can right click there and choose to Add reference. Then you browse to the binaries from the pther projects. (You might be able to point to the project itself too - I don't have VS in front of me at the moment.)
Also, It's a convention to use camel case for namespaces, so it should be MyNameSpace.
If the classes are in the same project, you might want to skip using mynamespace and refer to the class by Test intead of mynamespace.Test.
If these are both in the same project, please check that both files are included in the project and have the "Build Action" property set to "Compile". Please also check that all of these namespaces have exactly matching spelling and casing.

Cant type System.IO.Ports shorthand

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.

Categories