Runtime: NullReferenceException while running Nuget restore with current runtime.

Created on 7 Apr 2020  路  11Comments  路  Source: dotnet/runtime

In trying to get nuget to restore, I've already cleared my local caches, and rebooted.

I'm starting with a clean runtime repo by Executing the following sequence of commands:

$ git clean -xdf
$ cd src/libraries/System.Private.Xml
$ nuget restore

Of course, this doesn't work, and results in this output:

> MSBuild auto-detection: using msbuild version '16.6.0.16804' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\bin'.
> C:\Users\mrj00\source\repos\runtime\src\libraries\System.Private.Xml\tests\Misc\System.Xml.Misc.Tests.csproj : error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
> ... [numerous similar errors removed for clarity]
>   2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.1.802 [C:\Program Files\dotnet\sdk]
  3.0.100-preview9-014004 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.201 [C:\Program Files\dotnet\sdk]
  3.1.300-preview-015048 [C:\Program Files\dotnet\sdk]
A compatible installed .NET Core SDK for global.json version [5.0.100-preview.2.20176.6] from [C:\Users\mrj00\source\repos\runtime\global.json] was not found
Install the [5.0.100-preview.2.20176.6] .NET Core SDK or update [C:\Users\mrj00\source\repos\runtime\global.json] with an installed .NET Core SDK:
This indicates that nuget is looking for the 5.0 build, per the global.json file, and which I just removed.  I've included the above to confirm that nuget is utilizing the local 5.0 build.

Next, I build the SDK as follows:

$ git fetch upstream master
$ git checkout master
$ git merge upstream/master
Already up to date.
$ cd ../../..
$ ./build.cmd -subsetCategory coreclr-runtime -c Checked
$ ./build.cmd -subsetCategory coreclr-libraries -c Checked
$ cd .dotnet
$ export PATH=`pwd`:$PATH
$  cd ../src/libraries/System.Private.Xml
$ nuget restore

This results in the NullReferenceException, and outputs this information:

> MSBuild auto-detection: using msbuild version '16.6.0.16804' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\bin'.
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018: The "WriteRestoreGraphTask" task failed unexpectedly. [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at NuGet.Frameworks.AssetTargetFallbackFramework..ctor(NuGet.Frameworks1146378.NuGetFramework framework, IReadOnlyList`1 fallbackFrameworks) [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at NuGet.Commands.AssetTargetFallbackUtility.GetFallbackFramework(NuGet.Frameworks1146378.NuGetFramework projectFramework, IEnumerable`1 packageTargetFallback, IEnumerable`1 assetTargetFallback) [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at NuGet.Commands.AssetTargetFallbackUtility.ApplyFramework(TargetFrameworkInformation targetFrameworkInfo, IEnumerable`1 packageTargetFallback, IEnumerable`1 assetTargetFallback) [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at NuGet.Commands.MSBuildRestoreUtility.AddPackageTargetFallbacks(PackageSpec spec, IEnumerable`1 items) [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at NuGet.Commands.MSBuildRestoreUtility.GetPackageSpec(IEnumerable`1 items) [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext() [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at NuGet.Commands.MSBuildRestoreUtility.GetDependencySpec(IEnumerable`1 items) [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at NuGet.Build.Tasks.WriteRestoreGraphTask.Execute() [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\q2mkisgr.kt5.nugetrestore.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Users\mrj00\AppData\Local\Temp\NuGetScratch\z12lvu2w.p3m.nugetinputs.targets]
> 

I'm on Windows 10 Home (build 18363).
Visual Studio is community edition, 16.6.0, Preview 2
using git bash as the command line. Git version is 2.25.1.windows.1
HEAD is at 986518e2ad9 (master branch).

area-Infrastructure-libraries

Most helpful comment

All 11 comments

Tagging @ViktorHofer as an area owner

Please use dotnet restore instead and additionally note that you need to do an upfront restore and build in the repo root: build.cmd/sh -subsetCategory coreclr-libraries

@ViktorHofer
The build of the libraries was in the steps I documented in my initial report.
The result from dotnet restore was also a NullReferenceException, but without the stack trace. I had not mentioned this, as it was less informative.

@ViktorHofer
I've tried building this again. Today, I used this to build the libraries:

$ ./build.cmd -subsetCategory coreclr-libraries -runtimeConfiguration Checked

instead of:

$ ./build.cmd -subsetCategory coreclr-libraries -c Checked

which I used yesterday.

After the build, running either 'dotnet restore' or 'nuget restore' in the System.Private.Xml folder succeeds.

However, when I open the project in Visual Studio and attempt to build it there, I get the following output:

Error occurred while restoring NuGet packages: Invalid restore input. Duplicate frameworks found: 'netcoreapp5.0, netcoreapp5.0'. Input files: C:Users\mrj00\source\repos\runtimesrc\libraries\System.Private.Xmlsrc\System.Private.Xml.csproj.
1>------ Build started: Project: System.Private.Xml, Configuration: Debug Any CPU ------
1>System.Private.Xml -> C:Users\mrj00\source\repos\runtime\artifacts\bin\System.Private.Xml\netcoreapp5.0-Windows_NT-Debug\System.Private.Xml.dll
1>System.Private.Xml -> C:Users\mrj00\source\repos\runtime\artifacts\bin\System.Private.Xml\netcoreapp5.0-Unix-Debug\System.Private.Xml.dll
2>------ Build started: Project: System.Xml.RW.XmlReaderLib, Configuration: Debug Any CPU ------
3>------ Build started: Project: System.Xml.Xsl.XslTransformApi.Tests, Configuration: Debug Any CPU ------
4>------ Build started: Project: System.Xml.Misc.Tests, Configuration: Debug Any CPU ------
5>------ Build started: Project: System.Xml.RW.RwFactory.Tests, Configuration: Debug Any CPU ------
6>------ Build started: Project: System.Xml.RW.XmlWriterApi.Tests, Configuration: Debug Any CPU ------
7>------ Build started: Project: System.Xml.RW.XmlConvert.Tests, Configuration: Debug Any CPU ------
8>------ Build started: Project: System.Xml.XmlDocument.Tests, Configuration: Debug Any CPU ------
9>------ Build started: Project: System.Xml.XmlNodeReader.Tests, Configuration: Debug Any CPU ------
4>C:Users\mrj00\source\repos\runtime.dotnet\sdk\5.0.100-preview.4.20202.8\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file 'C:Users\mrj00\source\repos\runtime\artifacts\obj\System.Xml.Misc.Tests\project.assets.json' not found. Run a NuGet package restore to generate this file.
4>Done building project "System.Xml.Misc.Tests.csproj" -- FAILED.
3>C:Users\mrj00\source\repos\runtime.dotnet\sdk\5.0.100-preview.4.20202.8\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file 'C:Users\mrj00\source\repos\runtime\artifacts\obj\System.Xml.Xsl.XslTransformApi.Tests\project.assets.json' not found. Run a NuGet package restore to generate this file.
3>Done building project "System.Xml.Xsl.XslTransformApi.Tests.csproj" -- FAILED.
... numerous similar lines removed for clarity ...
29>Done building project "XsltCompiler.Tests.csproj" -- FAILED.
========== Build: 2 succeeded, 27 failed, 0 up-to-date, 0 skipped ==========

And once this has been opened in Visual Studio, I am again getting the NullReferenceException when trying to run either 'dotnet restore' or 'nuget restore' at the command prompt.

The build process shows it is using Visual Studio Community Edition 16.6.0, preview 2.1 (upgraded from preview 2 earlier today).
However, "./build.cmd -vs System.Private.Xml" is opening the project in Visual Studio Community Edition 16.5.3.
I'm not sure if that makes a difference.

@Anipik can you please take a look?

There's been a change in the build script (-subsetCategory is no longer available). My new build commands are:

$ ./build.cmd -subset Clr -c Checked
$ ./build.cmd -subset Libs -c Checked
$ ./build.cmd -runtimeConfiguration Checked -vs System.Private.Xml

When I then build the solution in Visual Studio, I get the following output (with numerous similar errors removed for clarity:

Error occurred while restoring NuGet packages: Invalid restore input. Duplicate frameworks found: 'netcoreapp5.0, netcoreapp5.0'. Input files: C:Users\mrj00\source\repos\runtimesrc\libraries\System.Private.Xmlsrc\System.Private.Xml.csproj.
....
4>C:Users\mrj00\source\repos\runtime.dotnet\sdk\5.0.100-preview.4.20202.8\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file 'C:Users\mrj00\source\repos\runtime\artifacts\obj\System.Xml.RW.RwFactory.Tests\project.assets.json' not found. Run a NuGet package restore to generate this file.
....
========== Build: 1 succeeded, 27 failed, 2 up-to-date, 0 skipped ==========

The System.Private.Xml project file referenced in the first error contains the following:

\

I changed it to:

\

This changed the initial error to:

NuGet package restore failed. Please see Error List window for detailed warnings and errors.

Accompanied by the same sequence of errors as before (due to the restore having failed). The Error List window does not contain any additional information. Running "nuget restore" or "../../../dotnet.cmd restore" at the command line both indicate a Null Reference Exception error.

I changed the TargetFrameworks tag to this:

\

At this point, I still get the same error in Visual Studio on building the solution. However, the "../../../dotnet.cmd restore" works at the command line. There is still no additional information in the Error List window regarding the Nuget failure. However, since it works at the command line, I presume, this is no longer the same error.

What I'm hoping for from this issue is a means to work around this Nuget issue in order to work with Visual Studio to compile and run the tests, etc. The issue on the Nuget.Home project is now nearly two years old.

My changes to the TargetFrameworks tag do not work as a workaround since compiling the XmlSortkeyAccumulator class depends upon the TargetFrameworks being what they are.

@mrj001 can you please try opening the solution with the -vs switch from the build script? E.g.

build.cmd -vs System.Text.RegularExpressions

That works around https://github.com/NuGet/Home/issues/5154 by doing a CLI dotnet restore before opening the solution in VS.

Tagging subscribers to this area: @safern, @viktorhofer
Notify danmosemsft if you want to be subscribed.

@ViktorHofer

$ ../../../build.cmd -vs System.Private.Xml

now successfully restores the projects prior to opening Visual Studio. However, in Visual Studio, one still gets the following when building:

Error occurred while restoring NuGet packages: Invalid restore input. Duplicate frameworks found: 'net5.0, net5.0'.
which, as I recall, is the Nuget bug referenced above.

Also a "dotnet restore System.Private.Xml" from the command line was successful.

I shared a workaround (till the actual NuGet issues is fixed) in https://github.com/dotnet/runtime/issues/20411#issuecomment-698381392. Let me know if that works, I will meanwhile close this issue as not actionable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sahithreddyk picture sahithreddyk  路  3Comments

GitAntoinee picture GitAntoinee  路  3Comments

aggieben picture aggieben  路  3Comments

jzabroski picture jzabroski  路  3Comments

iCodeWebApps picture iCodeWebApps  路  3Comments