12
votes

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

Frontend\src\Frontend\Startup.cs(65,49): Error CS0518: Predefined type 'System.Void' is not defined or imported C:\a\1\s\Frontend\src\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!

6
I think you are missing a dependency on the "System.Runtime" package.Pawel
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 wayIlya Chernomordik
Can you share the "dependencies" and "frameworks" section in project.json file?Eddie Chen - MSFT
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.Ilya Chernomordik

6 Answers

2
votes

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.

5
votes

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

1
votes

In my experience, I deleted the bin and obj folder and it worked. 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.

0
votes

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

0
votes

Going to the definition of the method on the line causing this error and updating the dependencies resolved this issue for me

0
votes

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.