Tag Archives: using

.NETproject compilation error. Type or namespace name could not be found. Visual studio automatically introduces dependency package (shortcut key)

Intro

Using visual studio to compile a. Net MVC project, many errors are reported in the following form:

CS0246	The type or namespace name 'xxx' could not be found (are you missing a using directive or an assembly reference?)
CS0246	Typ- oder Namespace-Name "xxx" nicht gefunden (fehlender Verwendungshinweis oder Assembly-Referenz?)

Screenshot:

Similar to in Java, if you directly use some class definitions without importing related packages, a similar error will be reported.

CS 0246 official document of error code: compiler error cs0246 | Microsoft docs

solve

In the above screenshot, the solution has been given:

is actually to add the correct class path using XXX .

However, in different versions of visual studio, does not introduce the same shortcut keys in the namespace where the class is located.

There are three ways to try:

Alt+Enter
Ctrl+.
Shift+Alt+F10

Of course, if you don’t know the shortcut key, but you know the full path (namespace, classname) of the class you are using, you should add using XXX at the beginning of the source code is OK.