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

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

    My case was same as discussed here but nothing solved it until I've removed the System.Core reference from the references list (Everything worked fine without it)

    hope it will help someone because this issue is quite frustrating

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

    I had a similar issue: The compiler was unable to detect a folder inside the same project, so a using directive linking to that folder generated an error. In my case, the problem originated from renaming the folder. Even though I updated the namespace of all the classes inside that folder, the project info somehow failed to update. I tried everything: deleting the .suo file and the bin and obj folders, cleaning the solution, reloading the project - nothing helped. I resolved the problem by deleting the folder and the classes inside, creating a new folder and creating new classes in that new folder (simply moving the classes inside the new folder didn't help).

    PS: In my case I was working on a web application, but this problem may occur in different types of projects.

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

    In my case I had a file built by external dependency (xsd2code) and somehow its designer.cs files were not processed by VS correctly. Creating a new file in Visual Studio and pasting the code in it did the trick for me.

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

    To anyone that is getting this error when they try to publish their website to Azure, none of the promising-looking solutions above helped me. I was in the same boat - my solution built fine on its own. I ended up having to

    1. Remove all nuget packages in my solution.
    2. Close and reopen my solution.
    3. Re-add all the nuget packages.

    A little painful but was the only way I could get my website to publish to Azure.

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

    I've no idea why this worked, but I removed the project reference that VS2015 was telling me it couldn't find, and added it again. Solved the problem. I'd tried both cleaning, building and restarting VS to no avail.

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

    I know this is kicking a dead horse but I had this error and the frameworks where fine. My problem was basically stating that an interface could not be found, yet it build and accessed just fine. So I got to thinking: "Why just this interface when others are working fine?"

    It ended up that I was actually accessing a service using WCF with an endpoint's interface that was using Entity Version 6 and the rest of the projects were using version 5. Instead of using NuGet I simply copied the nuget packages to a local repository for reuse and listed them differently.

    e.g. EntityFramework6.dll versus EntityFramework.dll.

    I then added the references to the client project and poof, my error went away. I realize this is an edge case as most people will not mix versions of Entity Framework.

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