37

I get this error when I try to build the project in Visual Studio Online:

…\Frontend\Startup.cs(65,49): Error CS0518: Predefined type 'System.Void' is not defined or imported
…\Frontend\Startup.cs(65,49): DNXCore,Version=v5.0 error CS0518: Predefined type 'System.Void' is not defined or imported [C:\a\1\s\Frontend\src\Frontend\Frontend.xproj]

It seems that the error happens in the place where I reference another library (package class library).

P.S. I had some conversation about this here: Easy way to build and deploy (to Azure) ASP.NET 5 in Visual Studio Team Services, but there was no answer after all, so I still cannot build it...

Web project.json:

"dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Web.Common": "1.0.0-*"
},

"frameworks": {
    "dnx451": { },
    "dnxcore50": { }
},

Library project.json

"frameworks": {
    "dnx451": { },
    "dnxcore50": {
        "dependencies": {
            "Microsoft.CSharp": "4.0.1-beta-23516",
            "System.Collections": "4.0.11-beta-23516",
            "System.Linq": "4.0.1-beta-23516",
            "System.Runtime": "4.0.21-beta-23516",
            "System.Threading": "4.0.11-beta-23516"
      }
    }
  },
"dependencies": {
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final"
  }

Update (problem and solution):

The problem was in the fact that my library reference was not in the same folder and the script by default does not run dnu-restore there, so I had to go one level up and start finding project.json recursively there

$SourceRoot = Split-Path -Path $PSScriptRoot -Parent

# run DNU restore on all project.json files in the src folder including 2>1 to redirect stderr to stdout for badly behaved tools
Get-ChildItem -Path $SourceRoot -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }

Thanks Eddie - MSFT for help!

5
  • 1
    I think you are missing a dependency on the "System.Runtime" package. Commented Jan 6, 2016 at 5:28
  • Where should I have this dependency? It's not by default in project.json in web project and it exist for coreclr, but not for clr in the library. P.S. Everything builds locally in VS by the way Commented Jan 6, 2016 at 8:40
  • Can you share the "dependencies" and "frameworks" section in project.json file? Commented Jan 6, 2016 at 9:19
  • I have added it to the post, I have changed the library target framework to match the web one because of R# issues (it does not find them as the same otherwise), but I have tried changing it back and it did not help either. I guess it should work properly with these web targets anyway as they are only more restrictive as far as I understood. Commented Jan 6, 2016 at 9:27
  • I have the same error even when I create a new .net winforms app project. Commented 2 days ago

17 Answers 17

35

Restart visual studio it will resolve the problem. It was the case for me.

Sign up to request clarification or add additional context in comments.

2 Comments

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
For what it's worth, @YanSklyarenko, it gave me the idea of restarting VS and my "system.void is not defined" error went away. So, thank you, Jean BIDI
20

Simply running dotnet restore in your terminal should solve the issue.

Comments

18

In my own issue, I rebuilt the entire solution and the errors just disappeared.

Edit:

This is most likely due to NuGet package restored.

3 Comments

To be fair, I experienced the same problem just now (only difference being that I was using the desktop edition of visual studio) and rebuilding the whole solution did indeed fix the "error". This suggestion somehow actually make sense... I fear the problem is just caused by some bug VS has with the "error cache?"
For me worked Clean, Rebuild, and then restart Visual Studio
I also had to update some nuget packages to get it fixed.
10

I had this problem after upgrading my VS2022, and my solution is:

  1. close visual studio
  2. delete the .vs folder
  3. restart the visual studio
  4. launch projects from the .sln file

Everything should then work fine.

Comments

8

In my experience, I deleted the bin and obj folder and it worked. Try closing the visual studio as well (if bin and obj folders are locked). However, for my colleague he deleted the entire solution folder and got the latest from TFS. He then compiled and rebuilt the solution and it worked.

Comments

4

I just experienced this issue in a Asp.NET Core 6 solution with several .NET Core 6 libraries.

Restarting VS 2022 didn't clear up the issue.

What did fix it? Deleting the contents of the main project's Bin and Obj directories. Then restarting Visual Studio.

3 Comments

Deleting folders didn't clear up the issue.
It definitely did for me. I suspect, based on the range of answers here, that there are several different root causes that can result in this same error. So if deleting the contents of the Bin and Obj folders didn't fix it for you then perhaps one of the other solutions will work for you.
work for me! My issue happened after VS 2022 updated.
3

Please remove bin and obj folders and rebuild.

Comments

2

I just reproduced this issue after updating the code in "PreBuild.ps1" script to only restore the "project.json" file for web project.

Original Code (Build Success):

Get-ChildItem -Path $PSScriptRoot\src -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }

Updated Code (Build fail with: Predefined type 'System.Void' is not defined or imported):

Get-ChildItem -Path $PSScriptRoot\src\WebProjectName -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }

So you need to check the PreBuild.ps1 script and the build logs for PowerShell step to check if the project.json files for Web project and Library project are both restored.

7 Comments

I am afraid I have the full \src in the Prebuild.ps1: Get-ChildItem -Path $PSScriptRoot\src -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }
@IlyaChernomordik Then check the build logs to see if the project.json file for Library project is been restored.
Let me check, can it happen that my project structure causes it? I have one project in \Frontend, the other (library) is not in the same folder but in \Common\Library
@IlyaChernomordik Yes. By default, the web project and library project are both placed under "src" folder. So the PreBuild.ps1 script can restore the project.json for both of them by default. If the library project is placed in other location, the project.json file won't be restored with that script by default.
I guess that is the problem then... The manual on how to do that did not really mention these details... I did put it in a common folder because it's a library that is going to be reused between different solutions so it's not quite correct... In the logs I have that: "Restoring packages for C:\a\1\s\Frontend\src\Frontend\project.json", but not for the other one, I suppose I'll have to amend the script a bit
|
1

Updating the NuGet Packges fixed the issue for me. Project > Manage NuGet Packages > Updates > Update All

Comments

0

I'm adding my own experience with that bug/issue.

Form my part I had to remove "System.Xml.XDocument": "4.0.10" from project.json to resolve the problem

Comments

0

My issue was being too trigger happy with the resharper import recommendations which had resulted in mscorlib.dll being manually referenced in the project. Removing it cleared everything up.

1 Comment

When I pass away, I want it inscribed on my tombstone that 'His cause of death was deleting the bin and obj folders and then cleaning and rebuilding the solution an infinite number of times' ... Please come back Digital and OpenVMS - all is forgiven ...
0

I had this error after GIT-Extensions Pull command.

After remove all write-protect attributes in the solution, the problem is solved.

Comments

0

In my case, the problem seemed to be that the dotnet sdk was not being found. On my Mac the sdks are in

/usr/local/share/dotnet/sdk

and I have version 7.0.102 there.

I adjusted the OmniSharp settings:

  1. Enable OmniSharp: Use Modern Net
  2. Specify the dotnet version in Omnisharp: SDK version, I specified 7.0.102

It's easier to find these two options if you specify "modern" in the settings search bar.

When I made those changes I was prompted to restart OmniSharp and immediately all the red warnings went away.

I have not experimented with variations of those settings, clearly it's not ideal to specify a specific dotnet version.

Comments

0

Unload and reload the offending project

Comments

0

If you are on a .net project, you need to install System, System.strings, System.... and other required packages using NuGet package manager.

I had this problem even with a fresh installation of Visual Studio 2026, and solved by installing required packages using NuGet package manager.

Comments

-1

Restarting Visual Studio worked for me, I haven´t gotten that problem since.

Comments

-2

In my case I was pointing to the wrong SDK version

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.