What to do when Visual Studio can't find a library your code needs
When you open a Visual Studio project and see red squiggly lines under code that references a library you don't have, the solution is usually one of three things: the library files are missing from your computer entirely, they exist but Visual Studio doesn't know where to find them, or the project file itself doesn't have the reference recorded. The fastest path depends on what kind of library you need — a NuGet package (the most common case), a local file you already own, or a system library that came with Visual Studio.
This guide walks through each scenario in the order you'll encounter them, starting with the method that solves the problem for most people.
Key Takeaways
- NuGet Package Manager is the standard way to add libraries in Visual Studio, and it handles downloading and linking automatically when you search for a package by name.
- If you already have library files on your computer, you can add them as references through the Solution Explorer without downloading anything new.
- Visual Studio sometimes needs you to rebuild the solution after adding a reference before the red lines disappear and IntelliSense works again.
- The most common mistake is confusing a package name with a namespace — searching for the wrong thing in NuGet wastes time, so check the official documentation for the library you need.
Adding a NuGet package through the package manager
NuGet is Visual Studio's built-in library marketplace. Most libraries you'll need — from JSON parsing to database tools — are published there, and NuGet handles downloading them and wiring them into your project automatically. This is the first method to try.
Right-click on your project name in Solution Explorer (the panel on the left showing your files and folders). Select Manage NuGet Packages. A new tab opens with a search box at the top. Type the name of the library you need — for example, if you need JSON handling, you might search for "Newtonsoft.Json" or "System.Text.Json". The search results show packages with read counts and version numbers. Click the package you want, then click the Install button on the right side. Visual Studio downloads it and adds it to your project automatically.
After installation completes, the red lines should disappear. If they don't, right-click your project name and select Rebuild. This forces Visual Studio to re-scan your code and recognize the new library. Wait for the build to finish — you'll see a message at the bottom saying "Build succeeded" or listing any remaining errors.
Adding a library file you already have on your computer
If someone gave you a .dll file (on Windows) or .so file (on Linux) or you downloaded one directly, you can add it without going through NuGet. This is less common but necessary when you're working with custom libraries or older code.
In Solution Explorer, right-click the References folder under your project name. (If you don't see a References folder, your project type may use Dependencies instead — right-click that instead.) Select Add Reference. A dialog opens with tabs on the left. Click Browse, then navigate to the folder where your library file sits. Select the file and click Add. The dialog closes and the library is now linked to your project.
Again, rebuild your project after adding the reference. If the red lines persist, double-check that you're using the correct namespace in your code — the file name and the namespace inside it are often different. For example, a file called "MyTools.dll" might contain a namespace called "CompanyName.Tools", and you need to use the namespace name in your code, not the file name.
Checking that your code uses the right namespace
A common source of confusion: the library is installed correctly, but your code still shows errors because you haven't told it which namespace to use. A namespace is a container inside a library that groups related code together. The library file and the namespace are not the same thing.
At the top of your code file, add a using statement (in C#) or Imports statement (in VB.NET) that names the namespace. For example, if you installed Newtonsoft.Json, you would add using Newtonsoft.Json; at the very top of your file. If you're not sure what namespace a library uses, check its official documentation or hover over the library name in your code — Visual Studio often suggests the correct namespace and offers to add it for you.
If Visual Studio shows a yellow lightbulb icon next to an error, click it. Often it will offer to add the using statement automatically. This is the fastest way to fix the red lines once the library itself is installed.
Rebuilding your solution when references don't take effect
Sometimes you add a reference and the red lines stay. This usually means Visual Studio hasn't re-scanned your code yet. A rebuild forces it to do so.
Go to the Build menu at the top and select Rebuild Solution. Visual Studio will recompile everything from scratch. This takes longer than a regular build but clears out stale information. Watch the Output window at the bottom — it will show you what's happening. When it says "Build succeeded", the red lines should be gone. If they're still there, the error message in the Output window will tell you what's actually wrong — usually a typo in the namespace or a version mismatch between what your code expects and what the library provides.
Finding the right package name when searching doesn't work
The most frustrating moment is typing a library name into NuGet and getting no results. This usually happens because you're searching for the wrong thing — either a namespace name instead of a package name, or a shortened version of the real name.
The solution is to check the official website or documentation for the library. For example, if you need a JSON library, searching for "JSON" returns hundreds of results. But the official Newtonsoft.Json documentation tells you the exact package name is "Newtonsoft.Json", not "JSON" or "NewtonsoftJson". Copy the exact name from the official source and paste it into the NuGet search box. You'll find it when ready.
If you still can't find it, the library may not be published on NuGet — it might be on a different package repository, or it might be distributed as a file you read directly. In that case, use the "Add a library file you already have" method above.
Handling version conflicts when multiple libraries need different versions
Occasionally you'll add a library and get an error saying another library you already have depends on a different version of the same package. This is a version conflict. Visual Studio usually resolves this automatically by choosing a version that satisfies both requirements, but sometimes you need to step in.
Open the NuGet Package Manager again and look at the installed packages. Find the conflicting library and note which version is installed. Then check the documentation for both libraries to see if they're compatible with a shared version. If they are, you can manually change the version number in the NuGet Package Manager — select the package, and a version dropdown appears on the right. Choose a version that works for both, then click Install. Rebuild your solution afterward.
If the libraries genuinely require incompatible versions, you may need to refactor your code to use only one of them, or contact the library authors to ask if they plan to update for compatibility.
Frequently Asked Questions
Why do I see red lines even after installing the package?
The most common reason is that you haven't rebuilt the solution yet. Right-click your project and select Rebuild. If that doesn't work, check that you've added the correct using or Imports statement at the top of your code file. The library being installed and the namespace being imported are two separate steps.
What's the difference between a package name and a namespace?
A package name is what you search for in NuGet — it's the name of the downloadable bundle. A namespace is a container inside that package that organizes code. They're often similar but not always identical. For example, the package "Newtonsoft.Json" contains the namespace "Newtonsoft.Json", but some packages have different names. Always check the official documentation to be sure.
Can I add a library from somewhere other than NuGet?
Yes. If the library is published on a different package repository, you can add that repository to Visual Studio's NuGet settings. If you have a .dll or .so file directly, use the "Add Reference" method and browse to the file. Some older or specialized libraries are distributed this way instead of through NuGet.
What does "Rebuild" do that "Build" doesn't?
Build compiles only the files that have changed since the last build. Rebuild deletes all compiled output and starts from scratch, recompiling everything. Rebuild is slower but clears out stale information that sometimes causes Visual Studio to miss new references. Use Rebuild when adding libraries or when a regular build doesn't pick up your changes.
How do I know which version of a package to install?
NuGet shows the latest stable version by default, which is usually the right choice. If your project targets an older version of .NET or C#, check the package documentation to see which versions are compatible. The package page on nuget.org lists which .NET versions each version supports. When in doubt, start with the latest stable version and only downgrade if you get compatibility errors.