60

I've installed the newly released version of Visual Studio 2017 and started a fresh ASP.NET Core project targeting .NET Core.

Out of the box, I'm getting the

The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)

error. Any idea what's causing this and how to fix it?

enter image description here

Also, looks like there are problems with NuGet packages as well: enter image description here

I also tried dotnet restore on the project through the command line and got the following error: enter image description here

P.S. Kind of disheartening that you get an error in a fresh new project in the latest version of Visual Studio 2017!

UPDATE: SDK version is v 1.0.1 -- see below: enter image description here

UPDATE 2: This is very strange. Looks like the original problem was due to NuGet package source pointing to a folder under Visual Studio 2015 folder. I unchecked it and left only nuget.org. With that my project seemed to have restored all the packages and when I started the project it loads up the standard ASP.NET page. But if I open startup.cs file, I get red squigglies all over the place but if I run the project, it works fine. What's going on here? enter image description here

UPDATE 3: I closed the project and VS 2017. I then restarted VS 2017 and opened the project and now it seems to be fine. And I'm not referencing the .NETStandard library 1.6.1 and everything seems to be working fine now.

3
  • Sorry overlooked. Do you see SDK under Dependencies? If not so, try adding <PackageReference Include="NETStandard.Library" Version="1.6.1" /> to your csproj.
    – Marcus S.
    Mar 12, 2017 at 1:51
  • 2
    I was about to post an answer just saying I finally closed VS 2017 and reopened it which fixed the problem for me, but then I saw your Update #3. Sometimes you just have to go back to troubleshooting basics :). I lost about 20 minutes on that one. I think for me VS 2017 just freaked out when I switched GitHub branches back and forth. Apr 14, 2017 at 20:14
  • Do not post images of code or errors! Images and screenshots can be a nice addition to a post, but please make sure the post is still clear and useful without them. If you post images of code or error messages make sure you also copy and paste or type the actual code/message into the post directly.
    – Rob
    May 19, 2018 at 0:14

22 Answers 22

43

I had the same issue in my Visual studio 2017 .Net Core application. I closed the Visual studio and re-open fixed everything.

2
  • 4
    Haha love it. Worked for me too. Sometimes the answer really is to turn it off and on again!
    – Mattkwish
    Jan 13, 2019 at 16:27
  • Same thing in VS2019. And it's not something that will pass by leaving VS open for a minute or so. Some perseverance may be necessary. In my case: close VS, re-open, close, go for dinner, re-open VS. Nov 9, 2021 at 17:17
38

Came across the same issue today. I had an old nuget source that no longer existed. So I went into Tools > Nuget Packet Manager and un-checked the wrong one. Hit "Ok", and then rebuilt the project, and it works great now. It seems like you stumbled onto it, but also wanted to verify that it fixed my issue, and it does.

enter image description here

3
  • 4
    Similar problem for me too, if someone has this problem check the Output from Package Manager. For me it was giving and error. Fixed that and it solved the problem.
    – Hugo Rocha
    Apr 26, 2017 at 14:44
  • 3
    Same problem here. Had an old myget source and removing it solved the all the build errors.
    – svarcoe
    May 3, 2017 at 20:51
  • 1
    I had to remove all of my sources except nuget and add them back in one at a time to find the culprit. But this was ultimately the fix. +1 Jun 12, 2018 at 19:51
21

I had the same problem, first when converting a VS2015 net core mvc web project to 2017 and then when trying to create a new core web application in 2017.

Went to Tools|NuGet Package Manager|Package Manager Settings - checked 'Allow NuGet to download missing packages' and 'Automatically check for missing packages during build in VS' and then clicked 'Clear All NuGet Cache(s)'.

Then re-built the solution - it found and loaded all the required packages and ran OK.

May not work for all cases but simple and worth a try.

4
  • I had the same problem, but it was a class library project. Even when creating a new project from scratch the SDK dependency was missing, cleaning the NuGet cache worked like a charm! Apr 13, 2017 at 19:20
  • 3
    Clearing the cache was also the solution for me. Apr 18, 2017 at 12:07
  • My problem was slightly different in that I [stackoverflow.com/questions/45279504/… ](could not add a controller)- just threw up error messages, however changing the settings to allow automatic downloads helped with this issue .
    – Myke Black
    Jul 24, 2017 at 13:04
  • 1
    Enabling NuGet package restore worked for me. Running it manually said everything was up to date despite a yellow warning icon next to the SDK deps tree item. Also dotnet restore seemed to not work, sadly.
    – Zack
    Aug 25, 2017 at 18:12
11

Multiple closing and reopening of VS2017 fixed it for me.

4
  • faced same problem today, your advise helped :) Aug 3, 2017 at 7:32
  • I also had to Clean Solution twice.
    – brichins
    Dec 8, 2018 at 16:41
  • Multiple closing and reopening of VS2017 some auto-magics...! thanks MS Dec 1, 2019 at 19:16
  • Three restarts with breaks in a few minutes (I googled the error at this time :) ) helped me. After restarts everything worked - I was able to build my WPF project (without changing anything). Rebooting the PC is not necessary, if it will be useful to someone.
    – Mikhail
    Jun 23, 2020 at 17:00
5

I had the same issue, the solution for me was to clear the NuGet cache. Tools > NuGet Package Manager > Package Manager Settings > Clear All NuGet Cache(s)

5

Check the version .NET Command Line Tools in CMD, just type dotnet --info. If version is 1.0.0, then try to install latest version .NET Core SDK from here.

enter image description here

4
  • My SDK version is 1.0.1. I updated the original post with a screen shot
    – Sam
    Mar 12, 2017 at 2:25
  • This is truly strange -- see update 2 under original post. The project runs but if I open the Startup.cs file, I see all kinds of red squiggly lines.
    – Sam
    Mar 12, 2017 at 2:30
  • I had the same problem.I decided it this way: 1. I deleted the dotnet folder and installed the latest version. 2. Then repaired VS via VS Installer. After that everything worked for me. Sorry for my English.
    – NDimo
    Mar 12, 2017 at 2:49
  • When I had this problem, the SDK item was missing from dependencies. It started when I renamed a project. So I created an empty Core Console app. If I created it with the default name, I had the SDK. If I supplied a name, no SDK. Very odd. This answer appears to have fixed it.
    – bbsimonbb
    Mar 22, 2017 at 13:06
3

Find the broken project and right click, Unload, right click, Re-load. Fastest fix for me.

If you get the problem while using the CLI, try doing nuget restore instead of dotnet restore as that sometimes pulls down packages that the dotnet CLI seems to miss.

1
  • This helped me. Just to add, My project was building successfully. But in error list it was showing errors. I unloaded, reloaded and rebuild. Jun 11, 2020 at 7:25
3

I have had the same issue with Visual Studio 2019 and .NET Core SDK 2.2.

These steps solved the problem:

  1. Close the Visual Studio
  2. Open the Visual Studio as Administrator
  3. Open the Solution
  4. Right click on Solution -> Restore NuGet Packages
3

I've tried all answers above. For me works only removal and adding the reference again described in the following steps:

  1. Open 'References' under the project.
  2. Right click on 'System' reference.
  3. Click on 'Remove'.
  4. Right click on 'References'.
  5. Click 'Add Reference...'.
  6. From right menu choose an 'Assemblies',
  7. In a search field type 'System'.
  8. Choose 'System' from the list.
  9. Click 'Add' button.
  10. IMPORTANT: Restart the Visual Studio.

'System' reference you can replace with any you need.

1

Try adding the following line above the other references in the csproj file

<Reference Include="netstandard" />

Reference screenshot

1

For me the problem was caused by my project having a custom IntermediateOutputPath. For some reason, if project_name.csproj.nuget.g.targets is not in obj subfolder of project folder, the error occurs.

Using default IntermediateOutputPath or keeping a shadow copy of project_name.csproj.nuget.g.targets in fake obj folder solves the problem for me.

1

This issue seems to be triggered by a myriad of reasons. Mine was caused by cloning directly from VSTS using Git Bash, my project directory had spaces in it. Git Bash changed those spaces in the path to %20. It was throwing off all the references in my project. So for anyone who tried everything else and are at their wits end, make sure %20 is not in the path.

1

So, I have cloned the repository from github and started getting this error.

It was my project uploaded from another machine. I later realized that I have used the materialdesign packages in my project.

I have uninstalled and reinstalled these packages and it fixed my issue.

0

Had the same problem. Uninstalled Application Insights from my projects using the nuget package manager. I'm not looking at that yet, I just wanted core and unit tests. Problem solved.

0

I also had the same problem. The is no SDK folder under the Dependencies one. Therefore, no Microsoft.NetCore.App libraries !

To solve this problem, in Nuget manager window, install any nuget which depends on .NetCoreApp (you can install for example Microsoft.AspNetCore or BundlerMinifier.Core from the Microsoft Visual Studio Offline Packages source).

The SDK will be restored by the same time.

Once it is back, you can uninstall the previously added nuget. The SDK will remain in place.

0

Not quite sure in which order vs 2017 trying to resolve packages. But my situation was following. In my VS2015 I had configured local and 3rd party source for nuget packages, newly installed version of 2017 loaded them too.

https://api.nuget.org/v3/index.json was first in list.

But vs2017 throwed an error that it can't restore .net core libraries from my another local repo.

After I unchecked all of them except https://api.nuget.org/v3/index.json, it had started to working normally.

0

I had this problem too, but not right now, this steps solved my problem: Choose Project -> Properties from the menu bar. In the Project properties window, under Configuration Properties -> General, make sure that Common Language Runtime Support is set to Common Language Runtime Support (/clr)

0

Simply opening the NuGet package manager and then the Visual Studio settings related to it - without changing anything - merely looking around, and when I closed out, the problem was gone.

This seems to be an intermittent issue that can come and go for no obvious reason.

0

None of the answers here worked for me so I'm posting what did work. My errors were mostly the same as the original poster but I also had:

Error loading meta data for 'Microsoft.Extensions.FileProviders.Embedded.2.0.1' hexadecimal value 0x1C invalid character

Every time I attempted to download a different nuget package or restore old packages I would see this error. I also saw the other errors such as:

type or namespace system could not be found


What worked for me:

  1. opened the filepath that the error said the bad metadata was in, which for me was C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.fileproviders.embedded\2.0.1
  2. Then, I put the contents of that folder into another folder I named "hiding".
  3. Then, I went back to the nuget package manager and tried to install a package, hoping to have the SDK restored. IOt worked successfully, and all my other errors were gone as well, and the fresh new project runs as it should!
0

The problem for me occurred when running my Visual Studio as Admin with a separate user-- I had created a Git Repo with the source files in the user documents of my normal account. When I created a new solution in that folder the above errors occurred. Try creating your project in a different place and see if the error still occurs.

0
0

I was facing the same issue when I created a new project (.net Core 2.2) in VS2019.In my case there was an Azure package which was creating the problem.I uninstalled it and the project started working fine. Run mentioned below command to uninstall the package.

Uninstall-Package Microsoft.VisualStudio.Azure.Containers.Tools.Targets -Version 1.7.10

0

I had the same problem. I cloned a github project and this error came. So I deleted the cloned project and then I cloned the project again and it worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.