CS0246
C# Programming Language
Severity: MinorWhat Does This Error Mean?
CS0246 means the compiler cannot find a type — a class, interface, enum, struct, or namespace — that you referenced in your code. This is a compile-time error. Your program will not build until it is fixed. The most common cause is a missing using directive, a missing NuGet package, or a typo in a type name. The error message tells you exactly which type name it could not find.
Affected Models
- .NET Framework
- .NET Core
- .NET 5+
- Visual Studio
- Visual Studio Code
- Rider
Common Causes
- Missing 'using' directive for the namespace that contains the class
- A required NuGet package is not installed in the project
- A typo in the class or namespace name — remember C# is case-sensitive
- The class is in a different project that is not referenced by this project
- The class was removed, renamed, or moved to a different namespace by a recent code change
How to Fix It
-
In Visual Studio, hover over the red-underlined type name and click the light bulb icon (or press Ctrl+.). It will often suggest 'using Namespace.Name;' — click it to add the using directive automatically.
This works for most standard .NET types. It is the fastest fix in most cases.
-
Check if the type comes from a NuGet package. Open NuGet Package Manager (Tools > NuGet Package Manager > Manage NuGet Packages). Search for the package and install it.
Example: Newtonsoft.Json types require the 'Newtonsoft.Json' NuGet package. Entity Framework types need the EF NuGet packages.
-
If the type is in a different project in the same solution, add a project reference. Right-click your project in Solution Explorer > Add > Project Reference, and select the project that contains the type.
Project references tell the compiler where to find types from other projects in your solution.
-
Check the exact spelling and casing of the type name. Search your codebase (Ctrl+Shift+F in Visual Studio) for the type name to confirm it exists and find its namespace.
If it is a type you wrote, verify the file is included in the project and the namespace matches what you expected.
-
If you recently upgraded a NuGet package or .NET version, some types may have moved to different namespaces. Check the package's documentation or changelog for migration notes.
For example, some types moved from System.Web to Microsoft.AspNetCore when migrating from ASP.NET to ASP.NET Core.
When to Call a Professional
CS0246 is a compile-time error you can fix yourself. If the type comes from a third-party library, check NuGet Package Manager to see if the package is installed. For multi-project solutions, verify that project references are set up correctly. If a type was recently moved or renamed in a refactoring, check version control history to see what changed.
Frequently Asked Questions
I have the using statement but still get CS0246 — why?
The using statement is correct but the type may live in an assembly you have not referenced. In .NET Framework, you needed to manually add references to assemblies (DLLs). In .NET Core and .NET 5+, most types are available automatically, but third-party types still need NuGet packages. Check the NuGet Package Manager to make sure the required package is installed.
What is the difference between CS0246 and CS0103?
CS0246 means a type (class, interface, struct, enum) was not found. CS0103 means an identifier — a variable, method, or property name — was not found. If you wrote 'List<string>' and it is underlined, that is CS0246 (missing type). If you wrote 'myVariable' and it is underlined, that is CS0103 (missing name).
How do I find which namespace a class belongs to?
The easiest way is to search the Microsoft documentation at docs.microsoft.com. Alternatively, right-click any working usage of the class and choose 'Go to Definition'. In Visual Studio, IntelliSense shows the namespace when you hover over a type. You can also search the NuGet.org website if you think it comes from a package.