简体   繁体   中英

Error "The type or namespace 'MyType' could not be found (or are you missing an assembly reference?)"

I've been getting an error "The type or namespace 'MyType' could not be found (or are you missing an assembly reference?)" , even though the namespace that 'MyType' lives in is added in the references. What is really weird is that when I try to run the solution, it does run with no problem (however I am suspecting it causes some other issues). I tried rebuilding the solution, rebuilding only the project with the namespace that this type is part of, and I also tried all the stuff mentioned here: "Are you missing an assembly reference?" compile error - Visual Studio I'm not sure what is going on. I thought it might have been a csproj file related issue, but the csproj file looks fine I guess:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>

I am a bit lost, does anyone know what this can be related to? Thank you in advance!

Like I mentioned in the comment above, I finally resolved the issue. I clicked "Add Reference" on the project that had errors in it, I saw the appropriate reference, as mentioned before. But even though I saw it I decided to click "Browse" in the references window and add it again. When I browsed to the csproj file that needed to be added as a reference, it had the wrong name. So the thing is, some time ago I changed the name of the csproj file of the project that had 'MyType' in it. Even though the project had the new name in my File Explorer and Solution Explorer, when I browsed to it from the references window in VS2019, it had the wrong name, so 'MyType' couldn't be found, because VS was looking for a project that had the wrong name and didn't exist anymore. Hopefully that'll help someone

PS: Another thing that I've notices and wanted to mention is that the project with 'MyType' was the git changes someone else pushed and I pulled. But I noticed after I pulled the changes, this project had a + icon instead of the lock icon, when I hovered over it, it said "Pending Add", which means, even though I pulled the changes, this change wasn't checked in on my end. So I closed VS, opened it back up and re-pulled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM