Add project as reference to another project - c#

I have two projects in the same solution.
One is an ASP.NET MVC 2 Empty Web Application,
the other is a Console Application.
In the first project i create a database with EF and a class to access the database.
What I want to do is add the first project as a reference to the console app project so i can use this class
I included it as a reference already it appears at the References, and after is include a using directive at the top of my console app i can even use code assistance. But when i compile i always get the error:
The type or namespace name 'DBModel' could not be found (are you missing a using directive or an assembly reference?)
How can i compile my projects?
Sincerely,
Zoli

From your description, if I'm getting it right,
That's often the case when you have different target .NET framework (Project properties, Application, Target Framework) - i.e. one is e.g. .NET 4.0 Client Profile - and the lib you're referencing is just .NET 4.0.

It's also possible that you're missing a reference to the Entity Framework in your Console application.
See this post for more info: http://www.dotnetcurry.com/ShowArticle.aspx?ID=617 (just below the middle, step 3).

Related

Reference manager is empty in vs 2017 .net core class library project

I'm trying to add reference to System.Configuration.dll assembly.
I'm using .Net Core, as it can be seen in my .csproj file:
<TargetFramework>netcoreapp2.2</TargetFramework>
(Output type of my project is set to Class Library.)
To do this, in solution explorer, I right-click on Dependencies of my project and then click on Add Reference.... Problem is that the opened Reference Manager is empty and there is no assembly I can add a reference to.
However, without referencing that assembly I'm able to write the following line without any build error:
using System.Configuration;
First Question: How is it possible that the above line gets successfully built, without me referencing that assembly?
If I try to use ConfigurationManager class to read data from app.config file (As told here ), I get an error complaining that:
CS0103 The name 'ConfigurationManager' does not exist in the current context
Question two: what can I do to solve that error? what's wrong with my code or project?
My case is not the same as this question and this is not a duplicate of that question.
Add Reference is for your local references. You need to use Nuget Package Manager in order to include references.
most importantly .Net Core does not use .Net Framework packages where ConfigurationManager is .Net Framework package.
You need to use .Net Core or .Net Standard libraries with .Net Core

.NET Code System.Web install source

Using Visual Studio Code on my mac book on sort of a Hello World type app. However, when I try to include a reference to System.Web, I get an alert stating:
The type or namespace name 'Web' does not exist in the namespace
'System' (are you missing an assembly reference?) [netcoreapp1.0]
Unnecessary using directive. [netcoreapp1.0]
I obviously supposed to add a reference System.Web, but giving the relative newness of this, I'm not sure of which nuget package I should apply to the project.
Any advice will be helpful.
Removed System.Web dependence is one of the benefit of ASP.NET Core, that by the way allows to build and run cross-platform ASP.NET apps. From ASP.NET Core documentation:
ASP.NET Core has a number of architectural changes that result in a much leaner and modular framework. ASP.NET Core is no longer based on System.Web.dll. It is based on a set of granular and well factored NuGet packages.
Don't know about source with nuget package descriptions, but you can start from searching in https://github.com/aspnet for appropriate project

Why my type or namespace name for project within solution isn't recognized?

I'm stuck with a project that I can't get "seen" in a reference by other projects in the same solution.
This is the error: Error 2 Metadata file 'C:\Documents and Settings\user\Desktop...\bin\Debug.dll' could not be found.
I've added the reference of course, and added the using directive for the namespace where it's used in class files. I remove the file, save, restart, and start anew, and it persists. Any ideas? I've been searching for hours, and it seems as though this can be caused by many things, none of which pertain to me. :/
It's a simple set of three class libraries and one windows forms project in the solution, VS 2010 Express, C#.
Within the same solution, but not within the same project? Are you sure you've declared your classes as public? They're internal by default.
Is one of your projects using .net 4 Client Framework and the referenced one isn't?
Have you added a project reference or a DLL reference between the projects? IS the name of the assembly you are referencing, really Debug.dll?
This is a little old, but thanks to the advice here I found my problem.
One project was using ".NET Framework 4 Client Profile" and the other ".NET Framework 4". I switched them both to use ".NET Framework 4" and it works fine now.

The type or namespace name could not be found [duplicate]

This question already has answers here:
Getting "type or namespace name could not be found" but everything seems ok?
(44 answers)
Closed 8 years ago.
I have a C# solution with several projects in Visual Studio 2010.
One is a test project (I'll call it "PrjTest"), the other is a Windows Forms Application project (I'll call it "PrjForm"). There is also a third project referenced by PrjForm, which it is able to reference and use successfully.
PrjForm references PrjTest, and PrjForm has a class with a using statement:
using PrjTest;
Reference has been correctly added
using statement is correctly in place
Spelling is correct
PrjTest builds successfully
PrjForm almost builds, but breaks on the using PrjTest; line with the error:
The type or namespace name 'PrjTest' could not be found (are you missing a using directive or an assembly reference?)
I've tried the following to resolve this:
Removed Resharper (since Resharper had no trouble recognizing the referenced project, I thought it might be worth a shot)
Removed and re-added the reference and using statement
Recreated PrjForm from scratch
PrjForm currently resides inside the PrjTest folder, I tried moving it to an outside folder
Loaded the solution on a different computer with a fresh copy of VS 2010
I have done my homework and spent far too long looking for an answer online, none of the solutions has helped yet.
What else could I try?
See this question.
Turns out this was a client profiling issue.
PrjForm was set to ".Net Framework 4 Client Profile"
I changed it to ".Net Framework 4", and now I have a successful build.
Thanks everyone!
I guess it figures that after all that time spent searching online, I find the solution minutes after posting, I guess the trick is knowing the right question to ask..
In my case I had:
Referenced DLL : .NET 4.5
Project : .NET 4.0
Because of the above mismatch, the 4.0 project couldn't see inside the namespace of the 4.5 .DLL. I recompiled the .DLL to target .NET 4.0 and I was fine.
PrjForm was set to ".Net Framework 4 Client Profile" I changed it to ".Net Framework 4", and now I have a successful build.
This worked for me too. Thanks a lot. I was trying an RDF example for dotNet where in I downloaded kit from dotnetrdf.
NET4 Client Profile:
Always target NET4 Client Profile for all your client desktop applications (including Windows Forms and WPF apps).
NET4 Full framework:
Target NET4 Full only if the features or assemblies that your app need are not included in the Client Profile. This includes:
If you are building Server apps, Such as:
ASP.Net apps
Server-side ASMX based web services
If you use legacy client scenarios, Such as:
o Use System.Data.OracleClient.dll which is deprecated in NET4 and not included in the Client Profile.
Use legacy Windows Workflow
Foundation 3.0 or 3.5 (WF3.0 , WF3.5)
If you targeting developer scenarios and need tool such as MSBuild or need access to design assemblies such as System.Design.dll
Another thing that can cause this error is having NuGet packages that have been built with a newer version of .NET.
The original error:
frmTestPlanSelector.cs(11,7): error CS0246: The type or namespace name 'DatabaseManager'
could not be found (are you missing a using directive or an assembly reference?)
Further up in the log I found this:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3275: The primary reference "[redacted]\DatabaseManager\bin\Release\DatabaseManager.dll" could not be resolved because it has an indirect dependency on the assembly "System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
The solution was to re-install the NuGet packages:
http://docs.nuget.org/docs/workflows/reinstalling-packages
I solved mine because the other project was coded with .NET 4.5 and the other one was coded 4.0
The using statement refers to a namespace, not a project.
Make sure that you have the appropriately named namespace in your referenced project:
namespace PrjTest
{
public class Foo
{
// etc...
}
}
Read more about namespaces on MSDN:
Using Namespaces
I encountered this issue it turned out to be.
Project B references Project A.
Project A compiled as A.dll (assembly name = A).
Project B compiled as A.dll (assembly name A).
Visual Studio 2010 wasn't catching this. Resharper was okay, but wouldn't compile. WinForms designer gave misleading error message saying likely resulting from incompatbile platform targets.
The solution, after a painful day, was to make sure assemblies don't have same name.
It is also possible, that the referenced projects targets .NET 4.0, while the Console App Project targets .NET 4.0 Client Library.
While it might not have been related to this particular case, I think someone else can find this information useful.
The compiled dll should have public Class.
I had the same issue. The target frameworks were fine for me. Still it was not working.
I installed VS2010 sp1, and did a "Rebuild" on the PrjTest. Then it started working for me.
Other problem that might be causing such behavior are build configurations.
I had two projects with configurations set to be built to specific folders.
Like Debug and Any CPU and in second it was Debug and x86.
What I did I went to Solution->Context menu->Properties->Configuration properties->Configuration and I set all my projects to use same configurations Debug and x86 and also checked Build tick mark.
Then projects started to build correctly and were able to see namespaces.
Changing the framework to
.NET Framework 4 Client Profile
did the job for me.
For COM/ActiveX references, VS 2012 will show this error right on using statement. Which is quite funny, since it's saying that may be you are missing a using statement.
To solve this: register the actual COM/ActiveX dll even if it's in the neighbor project, and add a reference through COM channel, not project channel. It will add Interop.ProjectName instead of ProjectName as a reference and this solves this strange bug.
If your project (PrjTest) does not expose any public types within the PrjTest namespace, it will cause that error.
Does the project (PrjTest) include any classes or types in the "PrjTest" namespace which are public?
just changed Application's target framework to ".Net Framework 4".
And error got Disappeared.
good luck;
:D
check your Project Properties, your Reference Paths should be empty like this:
Regards

Namespace in Referenced Project Present in Autocomplete Before Building, but Causes Compile Error After Building

I have a class library project which uses a namespace (e.g., "Cosmos.Creator.Util"). I then create a solution and windows forms application to test the library. From the windows form application, I add a reference to the library. So now I have two projects open in visual studio, a class library and a windows forms project. The forms project references the library.
When I edit my form's code, code autocompletion works correctly for the namespace that I use in the library. E.g., if I type "using Cosmos." I get autocomplete options like "Creator". But now if I build my solution, all of the "Cosmos" are red-underlined with the compile error: "The type or namespace name "Cosmos" could not be found (are you missing a using directive or an assembly reference?)".
For the purposes of the form application test, I placed my library code into a folder CosmosFormExample\Cosmos. When I check the reference from the form application, the reference is to CosmosFormExample\Cosmos\bin\Debug\Cosmos.dll, so that looks okay. I looked at the GUID referenced in the solution file and it matches the GUID of the project file Cosmos.csproj.
What has happened? How has the build caused my forms application to forget about the Cosmos namespace, despite the fact that it is still referencing the library project? Thanks much in advance.
Are you using VS2010 & .NET 4? If so you're probably using .NET 4 Client Profile instead of full fledged .NET 4. Go to project properties and check your Target Framework.
for more info: http://msdn.microsoft.com/en-us/library/cc656912.aspx
you need to check the framework you are using and the framework yout library was compiled for...

Categories

Resources