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

后端 未结 30 1085
北海茫月
北海茫月 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:45

    In my case I had a Class that was listed in the proper source folder, but was not registering in Solution Explorer. I had to do right click the project > Add Existing item and manually select that Class it said it was missing. Then everything worked fine!

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-22 09:47

    In my case the problem was that after changing namespace to exactly same as is in another project (intentionally), the name of assembly was changed as well by VS, so there were two assemblies with same name, one overriding the other

    0 讨论(0)
  • 2020-11-22 09:50

    We had a weird case of this that I just fixed in a solution. There was a hidden/whitespace character in front of a "using" statement in the main project. That project would build fine and the website worked fine, but the unit test project that referenced it could not be built.

    0 讨论(0)
  • 2020-11-22 09:50

    I encountered this problem when upgrading existing projects from VS2008 to VS2012. I found that two projects (the only two that I created) were targeting different .Net Frameworks (3.5 and 4.0). I resolved this on the Application tab of the projects by making sure that both projects had ".NET Framework 4" in the Target Framework box.

    0 讨论(0)
  • 2020-11-22 09:50

    I had same problem as discussed: VS 2017 underlines a class in referenced project as error but the solution builds ok and even intellisense works.

    Here is how I managed to solve this issu:

    1. Unload the referenced project
    2. Open .proj file in VS ( i was looking for duplicates as someone suggested here)
    3. Reload project again (I did not change or even save the proj file as I did not have any duplicates)
    0 讨论(0)
提交回复
热议问题