Can't find linked class - c#

I have two projects in the same solution and I have linked a class DatabaseFunctions.cs to the second one.
The problem is that when I reference it in the GUI_Teacher.cs I get the error:
Error CS0246 The type or namespace name 'DatabaseFunctions' could not be found (are you missing a using directive or an assembly reference?) Teachers application C:\Users\user1\source\repos\IASLSN\Teachers application\GUI_Teacher.cs

From the error, you are simply missing a reference.
Take the following steps to add a reference
Right click on the GUI_Teacher.cs project and click on Add Reference
From the left side of the Add Reference dialog, click on Solution
Select DatabaseFunctions.cs from the list and click OK to close the dialog.

In the source file DatabaseFunctions.cs you have something like
using System;
namespace SomeNamespaceName
{
public class DatabaseFunctions
{
}
}
To use the class in your GUI_Teacher.cs source file you need to add either using SomeNamespaceName; at the top or use the fully qualified type name SomeNamespaceName.DatabaseFunctions instead.
Keep in mind that the name of a sourcecode file like your DatabaseFunctions.cs for example has no connection to the name of a class or a namespace in that file. You can put a class like public class DatabaseFunctions { } in a file called foo.cs. And in the using directive at the top of your sourcefiles you provide a namespace and not a filename.

Related

C# Missing Reference

When running this code:
using System;
using System.Text.RegularExpressions;
namespace WebAutomationDemo
{
public class ExtractDigitsFromString
{
public static void Main(string[] args)
{
string inputData = "No 38, Bunder Garden Street, Perambur, Chennai - 600011";
var data = Regex.Match(inputData, "/s([a - z][A - Z]) +/s -/s/d[6]").Value;
Console.WriteLine(data);
Console.ReadLine();
}
}
}
I get the following error:
The type or namespace name 'RegularExpressions' does not exist in the namespace 'System.Text' (are you missing an assembly reference?)
This happens even after referencing System.Text.RegularExpressions assembly.
Are you still facing the same error,may be your assembly System is missing RegularExpressions method as stated by many.
Goto Object browser i.e click on any project solutions's references(expand) open any assembly will take it to take object browser window.
Now check whether the System.Text contains the RegualrExpressions method.
Object browser
If you follow the link there is an image of my object browser that do contains System.Text.RegularExpressions assembly.
If its missing ,download a valid assembly from MSDN
Below is one of link for a System.dll,download it or google it you can downlaod it easily.
https://www.dllme.com/dll/files/system_dll.html
Then goto references of your project and then add the downloaded assembly.

Error during Adding Class Library in My Project

I had created one Class library as BLL.Inside that one Class as ClsEmployeeMaster.
I want to use this library in my projet of Visitor Management.
when i was trying to add this as reff. then it added successfully but when I was start to Build then errors occurs as :
Error 5 The type or namespace name 'ClsEmployeeMaster' could not be
found (are you missing a using directive or an assembly reference?)
so What to do??
It is not enough to add a reference to your BLL. If you want to use the classes defined in your BLL you need to name them with the full namespace. Something like
MyCompany.MyBLL.ClsEmployeeMaster em = new MyCompany.MyBLL.ClsEmployeeMaster();
or you can simplify your typing with
using MyCompany.MyBLL;
....
ClsEmployeeMaster em = new ClsEmployeeMaster();
Open the class file that you have created.
Check the namespace written above the class.
for example
namespace MyCompany
{
class BLL
{
...
...
}
}
then add that namespace to your current .cs
using dllName.MyCompany;

Why can Visual Studio detect which "using" is needed, but then say the type or class which provoked the addition of the reference does not exist?

On trying to build, all of a sudden (a couple of days since I worked on this project) I get:
"The type or namespace name 'IO' does not exist in the class or namespace 'OpenNETCF' (are you missing an assembly reference?)"
But when I comment out that line (using OpenNETCF.IO.Ports;), I get:
? OpenNETCF.IO.Ports.Handshake (multiple choices...)?
When I click that, the choices are two:
OpenNETCF.IO.Ports.Handshake
- and:
OpenNETCF.IO.Serial.Handshake
As the code in this unit deals with printing, I select "Ports" (rejecting "Serial" because of its yin/yanginess to "Parallel"). So it then adds back the using I had which it complained about (using OpenNETCF.IO.Ports)...and then it's back to the original err msg.
Yet I do have several OpenNETCF items in my References, namely:
OpenNETCF
OpenNETCF.Data
OpenNETCF.Drawing
OpenNETCF.Net
OpenNETCF.Phone
OpenNETCF.VisualBasic // I don't know why, this is a C# project
OpenNETCF.Web.Services2
OpenNETCF.Windows.Forms
OpenNETCF.WindowsCE.Forms
OpenNETCF.Xml
What could possibly cause this chicken-and-egg tail-chasing exercise in frustration?
Odder yet, I get, "The type or namespace name 'Windows' does not exist in the class or namespace 'OpenNETCF' (are you missing an assembly reference?)" pointing to this using in another .cs file:
using OpenNETCF.Windows.Forms;
...and yet that using is grayed out as being unused at any rate, but when I comment it out, I get a lot of other errors purportedly because it's gone, such as on this line:
IntPtr hwnd = OpenNETCF.Win32.Win32Window.GetCapture();
The type or namespace name 'Win32Window' does not exist in the class or namespace 'OpenNETCF.Win32' (are you missing an assembly reference?)
UPDATE
In another episode of "Well Flip My Bits!" I just now compiled, got those err msgs about not being able to reconcile this line of code with what is installed and configured, etc., scrolled up to see that the "using" it was supposedly missing was there, compiled again, and now it compiles fine. What the blue blazes?!?!?!?
This sounds like a problem you see when you are building a project for a "Client Profile" .net version while referencing assemblies that are not supported in client profile.
Try changing your project's build settings to use a .net framework version that is not "Client Profile".
One can use the namespace using inside class also, so consider moving it there, if there are classes that use both than use the full name as in OpenNETCF.IO.Ports.Handshake handshake = new OpenNETCF.IO.Ports.Handshake()
And for the class using namespace:
using System;
namespace MyNamespace
{
using OpenNETCF.IO.Ports;
//...
}

missing a using directive or an assembly reference?

I am getting this error Error 4 The type or namespace name 'Sample' could not be found (are you missing a using directive or an assembly reference?) F:\oadmin\sea\Controls\Dlg.cs 11 7 Controls
here i added Samplein reference section,,,then i used it as Using Sample,,i dont know why i am getting this error
this is the class
namespace sample
{
public class Server
{
public class client
{
Bool sent = true
}
}
}
Can i share exe,,this Sample is an exe
Perhaps because your namespace is sample and not Sample?
So if your Dlg namespace is different it needs to have a using sample line not using Sample.
Or perhaps your class is in another project within your solution and you need to include the hierarchy of namespaces?
Your namespace "sample" is lowercase, but you are referring to it in uppercase "Sample" ...
EDIT: You Bool sent is internal, it cannot be accessed from outside of the assembly

Assembly access

If you have a assembly identity/namespace of Library.Testing.
Then you created another assembly with identity/namespace of Library.Testing.One
Library.Testing.One project references Library.Testing.
Why is it you have to use using Library.Testing; in your classes in Library.Testing.One to access anything in Library.Testing?
Example1:
using System;
namespace Library.Testing.One
{
// 'Library.Testing' is a reference in this assembly
public class foo : Library.Testing.BooBase
{
}
}
This does not work I get two exception
Warning 1 Load of property
'RootNamespace' failed. The string
for the root namespace must be a valid
identifier. Error 2 The type or
namespace name 'BooBase' does not
exist in the namespace
'Library.Testing.One.Library.Testing'
(are you missing an assembly
reference?)
Example2:
using System;
using Library.Testing;
namespace Library.Testing.One
{
// 'Library.Testing' is a reference in this assembly
public class foo : Library.Testing.BooBase
{
}
}
This works!
Adding a "using" for Library.Testing.One does not automatically bring everything in Library and Library.Testing into scope. The fact that the namespaces appear to be hierarchical is probably what's leading to your confusion.
Think of, for example, adding using System.Data.SqlClient to a file. That doesn't automatically bring everything in System and System.Data into scope.

Categories

Resources