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

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

    In my case, I find the reference in the VisualStudio have a triangle, and a exclamation mark as this image,

    then, I right click remove it, and add the dll reference correctly again, the problem was solved.

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

    I know its old, but I've found the same issue. My project did build, I then updated Visual Studio to the latest & the project wouldnt build as it couldnt find a type definition from a separate assembly. The other assembly built OK, the main project referenced it correctly & nothing had changed since it built OK.

    I cleaned the whole solution & rebuilt it, it failed. I built the assembly on its own, it built OK. The project didnt build. I cleaned & built multiple times, and it failed. I then called a colleague to look at it, when I built with him watching, it all built OK.

    I think Visual Studio tooling is the problem, especially as I just updated it.

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

    I got this error trying to make a build with a Visual Studio Team Services build running on my local machine as an agent.

    It worked in my regular workspace just fine and I was able to open the SLN file within the agent folder locally and everything compiled ok.

    The DLL in question was stored within the project as Lib/MyDLL.DLL and references with this in the csproj file:

    <Reference Include="MYDLL, Version=2009.0.0.0, Culture=neutral, PublicKeyToken=b734e31dca085caa">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>Lib\MYDLL.dll</HintPath>
    </Reference>
    

    It turned out it literally just wasn't finding the file despite the hint path. I think maybe msbuild was looking relative to the SLN file instead of the project file.

    In any case if the message you get is Could not resolve this reference. Could not locate the assembly then make sure that the DLL is in an accessible location to msbuild.

    I kind of cheated and found a message that said Considered "Reference\bin\xxx.dll" and just copied the dlls into there instead.

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

    In my case, adding the dll as a reference gave the type or namespace name could not be found error. However, copying and pasting the dll file directly in bin folder resolved the error.

    No idea why this worked.

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

    This one worked for me. In your class, where the class name is defined, eg: Public class ABC, remove one character and wait a little. You error list will increase because you have changed the name. Now put back the character that you have typed. This worked for me, hopefully it will work for you too. Good Luck!!!

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

    Had the same errors, my story was following: after bad merging (via git) one of my .csproj files had duplicated compile entries like:

    <Compile Include="Clients\Tree.cs" />
    <Compile Include="Clients\Car.cs" />
    <Compile Include="Clients\Tree.cs" />        //it's a duplicate
    

    If you have a big solution and more than 300 messages in the errors window it's hard to detect this issue. So I've opened damaged .csproj file via notepad and removed duplicated entries. Worked in my case.

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