Unable to add project reference in Visual Studio 2015 - c#

I previously asked a similar question regarding Visual Studio 2013 but now I'm running into the same problem with Visual Studio 2015 but it seems to work differently, which makes the previous answer not applicable to this question. This is my previous question: Visual Studio 2013 - How to debug a project within a solution
I'm attempting to add a project reference. I have a library I'm working on in a separate solution/project and a console application I want to use to test and debug the library.
I tried: Add Reference > Projects > Solution > Browse
But the open file dialog does not contain .sln files in the filter list and if I force it to display them by typing *.sln and then select the Solution I get:
"Please make sure the file is accessible and that it is a valid assembly or COM component."
What am I doing wrong? How do I properly add a Solution/Project reference?

For me issue was due to difference in Target framework. One was .NET Framework 4.5 and other was .NET Framework 4.5.2
Verify if the Target framework is same for your project and the project reference that you are trying add reference.
(Right click on project -> properties -> Application Tab(Target frame work))

Right click on your solution file in Solution Explorer window, click Add and select Existing Project...
Once the project is a part of the solution, you will be able to add project reference.

In case anyone else runs into this here is something that I found. I had almost the exact same issue in VS 2015. I created a console app and then a class library project but could not add a reference to the class library.
It turns out I didn't create a class library project as I had thought, but rather a class library (package) project. These are different things and I was unaware of what the (package) part meant when I selected it. This is for creating Nuget packages, apparently.
I'm not sure if this is something new to VS 2015 but I had not run across it before and it caused me some grief. The error message ('A reference to ClassLibrary1 could not be added') was totally worthless in trying to debug it.

You should add project to your solution first; after adding project to your solution, you can reference it.
To add an existing project to your solution:
Add reference menu:
Add references dialog:

In order to add a project reference, the project has to be part of the solution.

For me issue was due to a difference in the types of projects. One was a C# Windows forms project and the other project was a C# Universal Windows project.
The Windows Forms project couldn't reference the Universal Windows project. The error was "Unable to add a reference to project "XYZ".
It appears you can have a library shared between both types of projects by folloing this answer: What kind of class library works with both Universal and Winform projects?

I ended up having a different solution. I had three projects in the solution which referenced a NuGet package which was no longer available. I had the library locally but I was unable to add it. I found that because of the BUILD ORDER and DEPENDENCY of my projects, I had to add it to the project that was built first, then I could add it to the projects that were dependent on that project.

I had this problem today and I looked at the configuration manager for the solution. The projects had different platform settings. I made them both Any CPU and rebuilt. Then I could reference the project.

Related

Visual Studio 2019 16.11 - Can't update nor create WCF service reference in netstandard 2.1 project

I'm not sure when it disappeared, but I can't update my service references anymore, this is all new, I updated them like a month ago in a previous VS version without problems...
It's in a solution with a Xamarin Android project, the service references are in a .netstandard 2.1 project.
Also, if I try to add it manually from the Service References manager, weird errors pop up, and they don't make sense since using dotnet-svcutil is working:
We are experiencing this same problem in Visual Studio 2019 (16.11)
It is apparently fixed in an upcoming release. https://developercommunity.visualstudio.com/t/16110-update-service-reference-missing/1500425
This situation is common when I add references, delete references, and then re-add services with the same name. The type conflict seems to be caused by an old file that remains in a place where Visual Studio can still see it. All you need to do is clean it up before adding a new reference.
1.Delete the service reference in question.
2.Click the project name in the Solution Explorer to highlight the project.
3.Right-click the project reference.
4.Near the top of the context list, click Cleanup Items.
5.Add your service reference as usual.
Here is a similar example:https://github.com/dotnet/wcf/issues/3827

Visual Studio 2015 - Adding Reference to class library C# ASP.NET

I am trying to add references to class libraries under my Web Forms solution. I added several class libraries to the main solution (via File -> New Project -> Add to solution). When I tried to add references to them (both from the solution explorer window and the File menu), I received a popup stating simply: "Cannot add reference to ," with no additional error messages.
I verified that all projects are using the same version of the .NET Framework (4.5, NOT the client version) and the same target architecture (x64), as I have seen in other Stack Overflow posts.
I did try and add the reference via browse, and added the DLLs from the /bin/debug folder, and that actually worked. The namespaces were picked up and even shown in intellisense. My concern here is breaking these references during release builds and deployments.
I found a workaround for this problem.
When you head over to your solution and add a new project, you'll automatically be directed in the Web category. Instead head over to the Windows tab and pick that Class Library instead.

Adding references to other projects in Visual Studio 2012

I have a solution with 4 projects in it.
Test.Common
Test.Controller (Controllers for the Web project)
Test.Data (EntityFramework)
Test.Web (MVC4)
When I go to add a reference to my Data layer to my Controller project and browse to my Data project's directory, should I be using the dll from the 'bin/Debug' directory or the 'obj' directory? And, does it make a difference?
Neither.
You should add a Project reference (from the Solution section)
This will make Visual Studio resolve the reference from the project system, making features like Go to Definition and automatic rebuild work.
Outside your solution, you should add from bin.
You should be adding a reference to the Project in question, not its output. There is a 'Projects' tab on the 'Add Reference' dialog.
If the project is in your current solution you can make a reference to the project (Class Library) itself. This will offload the responsibility of configuration management (Debug, Release, etc) to Visual Studio.

.NET Intellisense: 2 projects in one solution

I have created a solution file consisting of these 2 projects: ProjectA and ProjectB (main). How can I get Visual Studio's Intellisense to work across the two projects?
For example:
ProjectA has ClassA with MethodA. While working on ProjectB, how do I get Intellisense to detect MethodA and any documentation on it without a build/rebuild of ProjectA?
You need to add a Project A as a project reference in Project B using the projects tab of the Add Reference dialog.
This will cause Visual Studio to read Project from the project system rather than the compiled DLL.
This offers a number of advantages:
You won't need to rebuild it
Visual Studio will realize that there is a dependency and automatically build project A when building project B
Editor features like Go to definition will work.
In the event that you already have a reference (and the Intellisense is still not showing up), this probably means you are referring to a dll already. You will have to remove the reference and add it again via the Add Reference dialog as mentioned above, or it will tell you that it already has that reference.

How to include source instead of a library in C# / Visual Studio?

I come from a long Java background and very new to C#. I was trying to run one of the starter kit applications from Windows phone and I am getting this error.
A first chance exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.WindowsPhone.dll
I am finding it hard to debug this because I am directly referring to the dll file under References pointing to Newtonsoft.Json.WindowsPhone. In Java, I would have searched for the library and downloaded the source to step into the exact location during debugging.
If that is possible, how would I do it in C# (as in how would i refer the library source for my project to pick up at run-time)? I am using the Visual studio 2010 Express Edition as the IDE.
Download the third party library you are dealing with
Add this library's project into your solution
In your project, remove the reference to the 3rd party library
Add a project dependency into your project, make it depend on the 3rd party library project you have just added to your solution
Compile and run, happy debugging
My best guess is you should download last release of Json.NET, remove the compiled library from your project's references and add reference to the source code project. (Add Reference... > Projects > Browse...)
Once you have stopped your program in the debugger, you can use the modules window to load the symbols for Json.NET. Obviously, you need to have the symbols on your machine so you can browse to them.
Failing that, you can switch to a project reference and include Json.NET in your solution as Dan suggested.
The easiest way is to download their latest build then inside visual studio right click your solution and under add menu select existing project point to project file of the library and click open button. after that u will be able to set brakepoint wherever u want.

Categories

Resources