I have 1 solution with 2 projects (TcpClient and TcpServer) in TcpProtocol namespace.
Folders:
TestProject/source/TcpProtocol.Client/TcpClient.cs
TestProject/source/TcpProtocol.Server/TcpServer.cs
I have added this to the TcpClient project:
using static TcpProtocol.Server; // for use static values in TcpProtocol.Client.
But when I try to build a project, I get the following error message:
"The type or namespace 'Server' does not exist in the namespace 'TcpProtocol' (are you missing an assembl reference?)"
It's strange, because reference exist, but under name of reference I see yellow triangle.
If instead of using static write like this in code all work fine:
TcpProtocol.Server.port = 8008;
Why doesn't it work with static? How do I fix it?
Never used that before but I would understand the docs that you have to target a type/class.
Your code sample seems to target a namespace...
Related
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.
I have web service (wcf c#) that uses entity framework.
It worked perfectly, but I updated the model and now I get error:
class is an ambiguous reference between NameSpace1.Class and
NameSpace2.Class.
I work in visualStudio 2012, and it suggests to change the type to NameSpace1.Class or NameSpace2.Class (Class is my class name and NameSpace1/2 are my namespaces names)
I choose the type I want - NameSpace1.Class, but then I get error:
The type or namespace name 'NameSpace1' does not exist in the
namespace.
but I dont understand - It does exist. and vs itself suggested me to choose it.
I tried everything: rebooting vs, cleaning and rebuilding the solution, and even rebooting my computer, but nothing helped.
maybe the error is wrong?
edit
well, the error comes from this line:
public IEnumerable<MyClass> GetMyClassList()
the options are: NameSpace1.MyClass or NameSpace2.MyClass.
I Click on the first, and it changed to:
public IEnumerable<NameSpace1.MyClass> GetMyClassList()
and then get error :
The type or namespace name 'Class' does not exist in the namespace 'Bll.NameSpace1'.
I think, that maybe the error occures because I have the namespace NameSpace1 twice: one in Bll.NameSpace1 (Bll is my current project) and the second in Reference with the name NameSpace1.
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;
//...
}
My solution wont compile. I am getting an error message when i try to compile my project:
Error 2 The type or namespace name 'Security' does not exist in the namespace 'Base' (are you missing an assembly reference?)
It is confusing, however, because i have referenced the project and that is the correct namespace! here's the solution setup
Solution Base
- Base.Domain
- Base.Security
- Base.Tests
- Base.WebUI
in Base.Security I have a custom role provider file like this:
namespace Base.Security.Providers
{
public class EFRoleProvider : System.Web.Security.RoleProvider
{
//code here
}
}
I have referenced Base.Security in Base.Tests and in Base.Tests I have the following file (that is giving me error):
using Base.Security.Providers;
namespace Base.Tests
{
class Program
{
static void Main(string[] args)
{
var a = new EFRoleProvider();
//more stuffs
}
}
}
I don't get it.. why can I not access Base.Security types from Base.Tests?
Make sure your projects are built against the same .NET version. I've had this issue when adding a reference to a .NET 3.5 project from a .NET 4.0 project.
To check/change the .NET version right click on your project, select properties, and under the "Application" tab make sure the "Target Framework" is identical for each project.
Your code looks correct, it's an issue with the way the reference is set up.
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