NuGet package restore failed Access to path is denied

This turned out to be a problem when NuGet packages are checked in to the source control system in folder packages.

The problem occurs when

  • Automatically restore missing NuGet packages is turned on in Visual Studio.
  • There are NuGet packages checked in to the source control system.
  • The TFS work space is a server work space.

When VS tries to restore NuGet packages, it will try to access the existing packages already in TFS, because the packages are read only as the workspace is a server workspace. VS will be denied access to the path to the package.

To solve this, either delete the existing packages, or turn off automatic package restore in Visual Studio.

The correct way is to have no packages checked in to the source control system, either keep the project up to date with NuGet, or create a local cache of packages.

Breakpoints cannot be hit when debugging C# in Visual Studio

When this happens, there can be a few reasons

-You attached to the wrong process.

-The build profile was changed to Release instead of Debug, thus no symbols are generated for debugging.

-You opened multiple instances of Visual Studio or programs that lock the PDB file, so when you make a new build the PDB file fails to be regenerated to match the new DLL.

-There are assemblies with classes with same name in the same namespace (for example DI may be configured to load different assemblies depending on some configuration). Visual Studio load the debug file for the wrong assembly when you are debugging some code. VS may assume that there is only one implementation of a a class in same namespace.

Steps to resolve

Make sure you attach to the correct process.

Make sure the build profile is Debug.

Clean and rebuild the solution.

If there are multiple assemblies with classes with the same name, try deleting the one that is not in use and then rebuild. Best option is to avoid classes with same name in same namespace. VS will be confused.

Last step, log out and log in again, or restart the computer to kill the processes that are locking the PDB. It could even be some Visual Studio bug.

Browsing functionality in a referenced binary

Keyword: object browser in Visual Studio

If you are working on a project with some binaries developed by the company previously and you don’t have access to the source code.

Aside from asking your colleague, use Visual Studio’s Object Explorer to browse the API in referenced binaries without the need of the source code.