I have 2 C# projects first one name is "Advocar" and the second one is "Import".
There is a class in Advocar project which we need to access to that from Import project. So in Import project I added reference to Advocar.
The problem is from Import project I recognizes all the Advocar classes except the new class that I just created in the Advocar. and when I build it, it say "The Type or namespace does not exist in the Advocar.Data.Inventory namespace. Are you missing an assembly?", but the class is exist in that namespace.
I build Advocar project and re-add the assembly to the Import project and it did not help. Both project are in .NET 2.0.
Any Idea please?
Check the access level of new class added into the namespace.
Ok. I found the solution although I dont know what would cause that.
since 40% of all the classes that I have are the same code, so to create a new class I just copied and pasted one of the existing class and made changes on that one.
So to solve my issue, I deleted the new classes and I just Add New Item and create a blank class and past the code that I needed to the new class and it fixed that.
Its look like some kind of caching issue that although you rename a class and so on, but it still has some record from past.
I have a solution that contains two projects developed in visual studio 2012 express, and both targeting the .net framwork 4.5.
the first "Dao" project purpose is to take data from a database. and take these data to the second project as a dll library
the second project "UI" purpose is to display data coming from dll library
when i added reference to the second project and wrote using statement, I got the following error:
The type or namespace name 'Dao' could not be found (a using directive or an assembly reference missing?)
I tried to change the target of the two projects to .net framework 4.0 and .net framework 3.5 , but I got the same error.
I also add this piece of code to be sure that the target is change but I got true :
using System;
using Dao; // error
namespace Ui
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Type.GetType("System.Reflection.ReflectionContext", false) != null);
Console.ReadKey();
}
}
}
What do I need to do to fix the problem? Thanks a bunch.
You need to add a reference to your Dao assembly from your UI assembly. Right Click on References, Add Reference. In the Projects tab, select your Dao project and hit OK.
First things first:
Add a reference to Dao - in source explorer right click references->Add->projects tab.
Add a using statement at the top of your code something like using Dao;
Ensure Dao is a public class
This way your code will know to reference Dao, it is usually better to create a new instance of Dao:
Dao example = new Dao();
Then when calling Dao you would call example instead, so example.(name of method)
Background: I am a novice in C#, and use Visual Studios 2010 Express.
I have a class (let's call it myclass) which I want to use in multiple projects. I used to add classes with Project->Add Existing Item... Which creates a copy of myclass.cs.
Now I just found out that when I build the original myclass.cs it creates a myclass.dll and places it in the release folder of my project.
But when I try to use this DLL, I get the following error:
The type or namespace name 'myclass' could not be found(are you
missing a using directive or an assembly refference?
Which is weird to me, because I already have referenced it (it is also in the Reference folder of my Solution Explorer). And I already have added this to my code:
using myclass;
So what am I doing wrong?
Update: When I tried my old method (add existing item -> myclass.cs) the error message goes away. So it's not a matter of spelling things correctly.
Add the dll first:
Click on references in your project-explorer in visual studio and add your dll then you can use it as you expected it.
Add the reference in your project and check that the target Framework version of that assembly fits the project.
Check the namespaces inside the assembly and then use them like:
using YourAssemblyNamespace.class
Okay so I found the answer myself. It turns out that when you use the using function, it automatically searches for all public classes in the namespace you want to use.
If it can't find a public class, it refuses to recognize the DLL.
Furthermore, not specifying a class makes it internal.
So:
class myclass // internal!
private class myclass // private!
public class myclass // only this makes it visible for others!
Everything was okay after changing class myclass into public class myclass.
I have to store some strings in the Settings file of my project. However, I am not able to access the Settings file to store the strings.
I definitely have accessed Properties file in an earlier project without facing any problems to store values.
Properties.Settings.Default.test = ...
MyApp.Properties.Settings.Default.test = ...
But here in the current project, I am constantly being driven mad by getting the Properties does not exist in the current context
Is there any setting or something that has changed because of which Properties does not appear in Intellisense?
I had this same problem occur when I had been copying and pasting code for plug-ins. It turns out that I had accidentally left the namespace of the other project in place when I copied. By changing the namespace back to the appropriate project, I was able to use the Properties.
at compile-time, Visual Studio generates a c# class which allows access to user and application settings. the generated class is defined in the default namespace specified in the project settings.
you may have to prefix any access to the Properties namespace with the default namespace defined in the project settings;
or you may change the default namespace: go to project settings, application tab, and edit the default namespace of the project.
Make sure your project has a settings file by going to the project properties and clicking on the Settings tab. If there is no settings file, it will tell you so and provide you with the option to create one.
I had this error when I accidentally had the wrong namespace as the Default namespace in the project properties.
To choose the default namespace, right click the project in the Solution ExplorerProperties->Application tab->Default namespace and check that it matches the namespace of your .cs files:
[...]
using System.Text;
using System.Threading;
namespace Correct.Namespace //<-- should match Default namespace field
{
static class Program
{
[...]
In my case, i have referenced a resource that has an Internal/Public access modifier. I have changed its access modifier to Public and the problem was gone.
First, try to recreate your project from scratch, if it's your testing environment. This step will recreate default namespace properly. You may skip this step if you are confident with your namespace configurations.
Second, if you still get Properties unrecognize as in my example where im trying to get data from sqlCon.
string connectionString = Properties.Settings.Default.sqlCon;
go to Project -> EventsandDelegates Properties as shown in the picture below. Make sure to create default settings file.
As soon as you create default settings under your Application settings, in my case it's SQL connection variable. Properties error will go away.
I just had the same problem. But the problem occured when I added a new setting to an already defined settings file (created a long time ago). Somehow adding a setting to the settings file made Visual Studio change the setting's namespace to the project default namespace (which had changed since the settings where modified last time).
So, because the settings access modifier was set to Internal, and the class trying to access the settings still where in the old previous namespace (still in the same project though), the settings became invisible from that class.
Quickest Solution i can offer is to double click on your resources.resx file if it exists, than change the Access Modifier Property at the top of the window from Internal to Public, Rebuild, which should compile successfully, then switch it back to internal and rebuild again. Should be fine after that.
In my case I was referencing one project (A) from another (B). Both in the same solution.
A has a public class (AClass) with a public static method. (AMethod)
I wanted to Test the results of this AClass.AMethod(...)
Visual Studio "colored" AClass in the call AClass.AMethod(...)
and I could right-click AClass and "Go to Definition",
which took me either directly to the source if I added referenced to the "Solution" project
Or to the DLL "outline" if I added reference to the DLL created by building Project "A"
But when I tried to build project "B" I got the error "AClass does not exist in current context"
It turns out Project B was targeting 4.5 and Project A was targeting 4.5.2
This answer helped: https://stackoverflow.com/a/15556365/1175496
Make sure you can see your setting in Settings.Designer.cs file. If not, try deleting and reentering the setting. For some reason, sometimes, the code auto generated by the tool does not include your setting. In that case, the setting wont be available in intellisense.
Funny, but in my case, I had defined the Properties in one project in the solution and was trying to access from another.
Hope this might help someone.
My issue with the "does not contain a definition for 'Properties'", was caused by adding a class to the namespace (JsonBreaker), with the same name as the namespace (ie JsonBreaker.JsonBreaker). Its notable that it was breaking compilation, as it seems some other folks are having a different experience.
namespace JsonBreaker {
public class JsonBreaker {
private readonly Options _opt = null;
...
I just changed the classname (and .cs filename) to Breaker, and my JsonBreaker.Properties.Settings.Default["InteractiveMode"] call started compiling again.
namespace JsonBreaker {
public class Breaker {
private readonly Options _opt = null;
...
I had this problem when running my web project in Visual Studio 2019. After unsuccessfully trying some of the solutions here, I closed VS2019 and re-opened the project from VS2017. Now the Properties namespace is being recognised.
My case:
I added a new database in the Solution Explorer
I tried:
string connectionString = Properties.Settings.Default.SlovickaSQLConnectionString;
My error:
I get:
Properties does not exist in the current context
Here is why:
I forget to add a new dataset in Data Sources panel.
This dataset has to be connected to the previously added database.
And now it works..
I have a solution in Visual Studio 2010 containing 6 projects (1 web application, 4 c# class libraries, 1 c# console application).
The console application is my test harness and use this to test external web services, output from methods from within my other libraries and general experimentation. This test console application has only one dependency on another project dependency, one of the C# libraries.
The referenced C# library is pretty simple:
namespace GowallaAPI
{
public class Gowalla
{
private static readonly ILog log = LogManager.GetLogger(typeof(Gowalla));
public SpotsInRadius GetGowallaSpotsInRadius(decimal lat, decimal lon, int radius) {
//snip
}
//other methods removed for brevity//
}
}
I have added to my console application a project reference:
And I've also right-clicked on References and selected Add Reference...
Then, I've gone to my console application and added;
using Gowalla;
Then hit build. I get this:
The type or namespace name 'Gowalla'
could not be found (are you missing a
using directive or an assembly
reference?)
I am completely baffled. I have:
Remove the dependencies completely (and then rebuilt with Gowalla references removed), and added them again.
I have removed the dependencies completely (like #1) and then added them as assemblies only (Add Reference...).
Checked that the target framework for both console application and class library is .NET 4.0 - they are.
Checked that all necessary items within the Gowalla class library are marked as Compile in the Build property.
Jiggled the build order of the project so that I am at least building the console application AFTER the library is built.
Done some shouting and swearing.
Given up and then returned.
Moved the Gowalla C# library out to its own project entirely and then referenced the assembly (like in 2).
Playing the having a constructor in Gowalla and not:
public Gowalla()
{
}
... and nothing has worked!
Can anyone see something obvious? Am I being utterly stupid? I have been on this for hours and I wonder quietly if this is a classic 'wood for the trees' moment...
Help appreciated.
EDIT 1: This is the Gowalla.dll exposed from Reflector:
ANSWER: After #gov's helpful suggestion to remove the GowallaAPI library and try and add something else I did that and started adding in the old code from the GowallaAPI library. Everything worked until I added:
private static readonly ILog log = LogManager.GetLogger(typeof(Gowalla));
log4net for some utterly bizarre reason kept throwing the build. Alas, after removing the line (the reference to log4net remains), the project built and worked perfectly thereafter. Thank you to #gov for setting me on the right path! :D
I had the exact same problem with log4net and it was resolved after changing target framework of the hosting project from ".NET Framework 4.0 Client Profile" to ".NET Framework 4.0"
I suggested him various things in the comments looks like one of them worked out.
#dooburt just forget about GowallaAPI and create a separate project like i say , sample.common and have a public class called utilities or so add that project here , just check a new project of type library and see whats the problem
Take a look at the .csproj XML, see if there is anything odd about the reference, one of these:
<Reference Include="Gowalla" ... />
<ProjectReference Include=".\path to\Gowalla.csproj" ... />
Have a look at the target framework of your class library and the test harness. I was having this error when the class library was set to .Net Framework 4 and the test harness was .Net Framework 4 Client Profile.