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

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

    First I would verify that your project's generated information isn't corrupt. Do a clean and rebuild on your solution.

    If that doesn't help, one thing I've seen work in the past for designer issues is opening up a windows forms project, then closing it again. This is a little chicken-entrails-ish, though, so don't hold your breath.

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

    [Facepalm] My issue was that I had added the dependency in the C++ way of doing things.

    Go to the project that won't build, open up the 'References' folder in Solution Explorer, and see if your dependency is listed.

    If not, you can 'Add Reference' and choose the dependency on the Projects tab.

    Boom Shankar.

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

    To solve this issue it can also help to delete and recreate the *.sln.DotSettings file of the associated solution.

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

    I know this thread is old but anyway I'm sharing, I have to install all third part dependencies of the imported assembly - as the imported assembly wasn't included as Nuget package thus its dependencies were missing.

    Hop this help :)

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

    You might also try eliminating the code you think you're having problems with and seeing if it compiles with no references to that code. If not, fix things until it compiles again, and then work your suspected problem code back in. Sometimes I get strange errors about classes or methods that I know are correct when the compiler doesn't like something else. Once I fix the thing that it's really getting hung up on, these 'phantom' errors disappear.

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

    Adding my solution to the mix because it was a bit different and took me a while to figure out.

    In my case I added a new class to one project but because my version control bindings weren't set I needed to make the file writable outside of Visual Studio (via the VC). I had cancelled out of the save in Visual Studio but after I made the file writable outside VS I then hit Save All again in VS. This inadvertently caused the new class file to not be saved in the project..however..Intellisense still showed it up as blue and valid in the referencing projects even though when I'd try to recompile the file wasn't found and got the type not found error. Closing and opening Visual Studio still showed the issue (but if I had taken note the class file was missing upon reopening).

    Once I realized this, the fix was simple: with the project file set to writeable, readd the missing file to the project. All builds fine now.

    0 讨论(0)
提交回复
热议问题