Getting “type or namespace name could not be found” but everything seems ok?

后端 未结 30 1075
北海茫月
北海茫月 2020-11-22 09:27

I\'m getting a:

type or namespace name could not be found

error for a C# WPF app in VS2010. This area of code was compiling fine

30条回答
  •  北海茫月
    2020-11-22 09:46

    When building the solution I was getting the same error (type or namespace ' ' could not be found). Below it I saw a warning stating that "the reference could not be resolved" and to make sure "the assembly exists on disk".

    I was very confused, because my DLL was very clearly in the location that the reference was pointing to. VS didn't seem to highlight any errors, until I tried to build the solution.

    I finally realized the problem (or at least what I suspect was the problem). I was building the library file in the same solution. So even though it existed on the disk, it was being rebuilt in that location (somehow in the process of the library getting rebuilt my other project - in the same solution - that referenced the library must have decided that the library didn't exist)

    When I right-clicked on the project and built that only, instead of the entire solution, I didn't get the error.

    To fix this problem I added the library as a dependency to the project that was using it.

    To do this:

    1. I right-clicked on my Solution in the Solution Explorer and selected "Properties"
    2. Then in "Common Properties" I selected "Project Dependencies".
    3. Then in the Projects drop-down menu I selected the project that relied on the library, and
    4. Checked the box next to the library found under "Depends On"

    This ensures that the library project gets built first.

提交回复
热议问题