.I m very new to programming, and I think I'm loosing my mind trying to understand what's the problem here. Does Anyone have any suggestions?
The Test Project has Reference set to OrderManagementSystem.Domain and OrderManagementSystem.Controllers.
The Controllers Class is Public .
Im able to access Classes from Domain Namespace , but not Controllers??
What did i do wrong?
This error is because your class name is Controllers and namespace also contains .Controllers.
Either update the name of class or remove .Controllers from the namespace OrderManagementSystem.Controllers
In Controllers.cs file,
using Systems;
....
//Remove .Controllers from namespace
namespace OrderManagementSystems
{
public class Controllers
{
//Your code
}
}
Related
I created a new Razor Class Library (using "dotnet new razorclasslib"). I then created a folder called Models in the new library and it contains a class with the following test code:
using System;
namespace TestLibrary.Models
{
public class TestModel
{
public string TestMethod { get; set; }
}
}
However, when I try to use this class from the web application project (by referring to it as TestLibrary.Models.TestModel) I keep being told that the TestLibrary.Models namespace doesn't exist. The exact error is:
The type or namespace name 'Models' does not exist in the namespace 'TestLibrary' (are you missing an assembly reference?) [TestApplication]
I'm assuming I'm missing something simple, just can't figure out what.
This issue was somehow related to the issue posted here: Razor Class Library MSBuild MSB4062 Error During Compile. Once that was resolved this issue went away.
I have a simple console app with the namespace of
something.service.console
The problem is when I try to use
Console.WriteLine("something");
I get compile error: The Type or namespace name "WriteLine" dos not exist in the namespace something.service.console.
So unless I use
System.Console.WriteLine("something");
The C# compiler is trying to resolve the method WriteLine to the incorrect namespace ("something.service.console").
In this scenario is it possible to force the compiler to resolve the Console.WriteLine to the correct namespace "System" (instead of renaming my namespace :))?
Thank you.
The compiler will find the namespace something.service before it finds the namespace System so it will assume that
Console.WriteLine("something");
actually means
something.serviceConsole.WriteLine("something");
and hence your error.
Two possible solutions are to either fully qualify the namespace when you have issues like this:
System.Console.WriteLine("something");
or change the name of your namespace so it's not something.service.console but something.service.somethinglese.
You could "force" it like this:
using SysConsole = System.Console;
Now whenever you use Console in is refering to System.Console
public class Console
{
private void Test()
{
SysConsole.WriteLine("something");
}
}
Note: There really is nothing bad about using:
System.Console.WriteLine()
and you should avoid using classnames that already exist in the .NET Framework.
Using a C# 6 feature "using static" you can change the code to in order to avoid the ambiguous name Console without cluttering the code.
This would make sense, if a lot of System.Console.WriteLine calls occur in the code.
using static System.Console;
namespace SomeNamespace.Console
{
public class SomeClass
{
public void SomeMethod()
{
WriteLine("abc");
}
}
}
I have this control:
public partial class controls_UploadedImageView : System.Web.UI.UserControl
{
And in a static function I have this code:
using (var ctl = (controls_UploadedImageView)tmp0.LoadControl("~/controls/UploadedImageView.ascx"))
{
ctl.RenderControl(h);
}
However the cast to `` fails:
The type or namespace name 'controls_UploadedImageView' could not be
found (are you missing a using directive or an assembly reference?)
I can't work out how to cast the control properly so I can set it's properties before rendering.
Update
Turns out that as my project is a website project and not a Web Application, it is causing this issue. A solution is to convert the entire project to a web application but this looks time consuming and fiddly. Does anyone have any solution that doesn't require me to convert the entire project?
I think I have fixed this before by using an interface.
Create an interface in the app_code folder
public interface ICustomControl
{
... add any extra methods here
}
when you declare the class for your user control, include that interface
public partial class controls_UploadedImageView : System.Web.UI.UserControl, ICustomControl
then use that interface.
using (var ctl = (ICustomControl)tmp0.LoadControl("~/controls/UploadedImageView.ascx"))
This is all from memory, but hopefully it gets you close to the solution. I'll check my code later if its not helping.
Try simply adding a namespace to your .ascx.cs (may need to update the .ascx also). Then add a using <namespace>; statement to the class that needs to reference that control.
Ex:
namespace MyFancyNamespace
{
public partial class controls_UploadedImageView : System.Web.UI.UserControl
{
}
}
and...
using MyFancyNamespace; //this goes at the top of your class.
using (var ctl = (controls_UploadedImageView)tmp0.LoadControl("~/controls/UploadedImageView.ascx"))
{
ctl.RenderControl(h);
}
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;
Using .NET 2.0, C#, Windows Forms development, Enterprise Library 3.1.
We have a project namespace (call it Project). We also have several sub-namespaces inside of that project, for example Project.Namespace1, Project.Namespace2, etc.
In one class, we define enums and such to be used with the Enterprise Library Logging block, like this:
namespace Project.Logging
{
public static class Logging
{
public enum LogPriority
{
// enum values here
}
}
}
In another class, I use the enum values so I need to declare a using statement. Same project, so there is no assembly to reference, right?
If I declare the using inside of the local namespace, like this, it works fine:
namespace Project.SomeName
{
using Project.Logging;
// code referencing the Logging enum
}
However, if I put the using statement outside of the local namespace declaration, I get the "type or namespace name 'LogPriority' does not exist in the namespace 'Project.Logging'... Like this:
using Project.Logging;
namespace Project.SomeName
{
// code referencing the Logging.LogPriority.whatever
}
Why is this? Has anyone run across this before?
I have run into similar (though not exactly the same) problems before when using a class that has the same name as its namespace.
Oddly enough it seemed to compile ok on some developers pc's but not on others. In the end we made sure that no namespace contained a class of the same name.
namespace Project.Logging
{
public static class Logging // this is what caused the probems for me
{
}
}
I also had a wired error. I cannot find any namespace which is coming from different assemblies, but begins with executing assembly name.
Finally, I found out that I have set the target framework to .NET framework client profile.
Yes, most likely you have an unusual value set for the "Default Namespace" in your project properties. I would validate the project configuration.
We ran into this issue before and it all went down to ambiguous naming of the namespace and the class name.
When we tried to have our namespace as Services.Web.xxx and also add in a service reference as Services.Web.xxxx and ALSO add a references to an assembly that was named Services.Web.xxx you can only imagine the problems we ran into.
In the end to fix it we simply did a rename to make sure that there was only one instance of the Services prefix
Also you could do the following and create an alias to LogPriority to LogEnum:
using LogEnum= Project.Logging.Logging.LogPriority;
namespace Project.SomeName
{
internal class MyClass
{
public MyClass()
{
LogEnum enum1 = LogEnum.None;
}
}
}
namespace Project.Logging
{
public static class Logging
{
public enum LogPriority
{
None,
Default
}
}
}
It definitely can make a difference if you have usings inside or outside the namespace. There is a good discussion here, and it is likely to be related to your default namespace settings.