Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException in Microsoft.NET.Build.Tasks.ProjectContext after broken restore #39316

Open
drewnoakes opened this issue Mar 8, 2024 · 37 comments
Assignees
Milestone

Comments

@drewnoakes
Copy link
Member

I was trying to update some packages and got into a funky state. The following exception appeared in the VS Error List.

MSB4018	The "ResolvePackageAssets" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.NET.Build.Tasks.ProjectContext.<>c__DisplayClass31_0.<GetTopLevelDependencies>b__3(String projectFileDependency)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.ComputePackageExclusions()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	VisualStudioEditorsSetup	C:\Program Files\dotnet\sdk\8.0.300-preview.24122.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets	266		

I don't have clear repro steps unfortunately.

The exception appears to be within this block of code:

.Select(projectFileDependency =>
{
int separatorIndex = projectFileDependency.IndexOf(' ');
string libraryName = separatorIndex > 0 ?
projectFileDependency.Substring(0, separatorIndex) :
projectFileDependency;
if (!string.IsNullOrEmpty(libraryName) && libraryLookup.ContainsKey(libraryName))
{
return libraryName;
}
return null;
})

At a glance it seems like either projectFileDependency would be the most likely null, meaning a dependency group contains a null dependency, which seems problematic. It might be a bug on the NuGet side. If I see this again, I'll grab a copy of the assets file.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Mar 8, 2024
Copy link
Contributor

Thanks for creating this issue! We believe this issue is related to NuGet tooling, which is maintained by the NuGet team. Thus, we closed this one and encourage you to raise this issue in the NuGet repository instead. Don’t forget to check out NuGet’s contributing guide before submitting an issue!

If you believe this issue was closed out of error, please comment to let us know.

Happy Coding!

@baronfel
Copy link
Member

baronfel commented Mar 8, 2024

reopening and retagging - this should be kept open until we can prove a problem on the NuGet side.

@hansmbakker
Copy link

hansmbakker commented Apr 16, 2024

I have this problem with a .NET MAUI project after updating to

  • SDK 9.0.100-preview.3.24204.13
  • updated workload
  • updated target frameworks to net9.0-android in the projects

Operating system is Windows 11 23H2, build 22631.3447

dotnet restore / dotnet build works well, but I get this error with Build / Rebuild in Visual Studio 17.10.0 Preview 3.0

drewnoakes added a commit to drewnoakes/project-system that referenced this issue Apr 29, 2024
@drewnoakes
Copy link
Member Author

drewnoakes commented Apr 29, 2024

I'm hitting this again now. I've pushed the state that repros it to: https://github.com/drewnoakes/project-system/tree/dotnet-sdk-issue-39316-repro

Project: ProjectSystemSetup
File: C:\Program Files\dotnet\sdk\8.0.300-preview.24203.14\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets
Line: 266

@stephentoub
Copy link
Member

stephentoub commented May 18, 2024

I'm hitting this as well. I get it even from the command-line, e.g. doing a dotnet clean I got:

    C:\Program Files\dotnet\sdk\9.0.100-preview.4.24210.38\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:
      The "ResolvePackageAssets" task failed unexpectedly.
      System.NullReferenceException: Object reference not set to an instance of an object.
         at Microsoft.NET.Build.Tasks.ProjectContext.<>c__DisplayClass31_0.<GetTopLevelDependencies>b__3(String projectFileDependency)
         at System.Linq.Enumerable.IteratorSelectIterator`2.MoveNext()
         at System.Linq.Enumerable.IEnumerableWhereIterator`1.ToArray()
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.ComputePackageExclusions()
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
         at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
         at Microsoft.NET.Build.Tasks.TaskBase.Execute()
         at Microsoft.NET.Build.Tasks.TaskBase.Execute()
         at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost
       taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

@xaviergxf
Copy link

xaviergxf commented May 23, 2024

I'm also hitting the same issue when trying to setup Aspire to work with a monolith. Is there a workaround?

C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly.
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.LockFileExtensions.<GetProjectFileDependencySet>g__IndexOfWhiteSpace|6_1(String s)
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.LockFileExtensions.GetProjectFileDependencySet(LockFile lockFile, String frameworkAlias)
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.<WritePackageDependenciesDesignTime>g__GetPackageDependencies|59_0()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WritePackageDependenciesDesignTime()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroup(Action writeItems)
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroups()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.Write()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteToCacheFile()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

@7Fathoms
Copy link

As @hansmbakker suggested, using the dotnet cli is one workaround. Once compiled then VS seems to work. Another option is to copy the AndroidManifest.xml file from the Platforms/Android folder to the same location as the Maui project file.

@drewnoakes
Copy link
Member Author

I've been hitting this every few days, usually following a branch switch that changes what packages/versions the solution has.

@Evangelink
Copy link
Member

I am also hitting this issue (seems consistent for now locally).

@Rohith-Reddy-k
Copy link

+1 unable to build the project using visual studio, but able to build via developer command prompt using msbuild

@drewnoakes
Copy link
Member Author

Is everyone who hits this using central package versioning? (Or is anyone seeing this without using CPM?)

@Evangelink
Copy link
Member

I am using CPM yes

@hansmbakker
Copy link

I'm also using CPM indeed.

@7Fathoms
Copy link

Me as well.

@xaviergxf
Copy link

CPM as well

@Rohith-Reddy-k
Copy link

Did anyone recently update their targeting framework to .net8.0? For me I am suspecting this is due to that.

@jflevesque-genetec
Copy link

I'm also hitting this issue. I have a 2nd Directory.Packages.props in a test folder to add GlobalPackageReferences for test dependencies and while I have this file present, I'm getting the same error as the others. If I remove that file, the error disappears. Possibly related?

@lsoft
Copy link

lsoft commented Jul 15, 2024

Same issue. CPM, net8-android, Directory.Packages.props - all ingredients are here.

@mungk
Copy link

mungk commented Jul 18, 2024

I encountered this issue when I was uninstalling a particular package. I removed the PackageVersion entry for the library from my Directory.Packages.props but still had the PackageReference for that library in the project. In that state, I received this error. After I removed the PackageReference tag from the projects, the error went away.

In the past, when this situation occurred there was a different error message, but I can't quite recall what it used to say. Something about a missing package version I thought, but not positive.

@rick-micpoint
Copy link

rick-micpoint commented Jul 25, 2024

I have two of the issues described above. First I had some missing package versions, which results in the exception instead of a proper error message. Once I fixed those I was left with one project that I couldn't fix, a .NET MAUI project. This one keeps throwing the exception despite fixing the versioning.

Building it from the command line did work however, and after doing that once I can build it from visual studio as well.

The tools need to be made more resilient and should be able to properly report edge errors instead of crash. And the issue with android is just a bug in itself.

@giulianob
Copy link

Getting this error but it was due to a package that was missing from my Directory.Package.Props. I received the null ref exception when using msbuild or dotnet msbuild but dotnet build shows the correct error and once fixed it worked.

> dotnet msbuild
MSBuild version 17.11.3+0c8610977 for .NET
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly. [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ProjectContext.<>c__DisplayClass31_0.<GetTopLevelDependencies>b__3(String projectFileDependency) [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext() [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray() [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.ComputePackageExclusions() [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash) [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task) [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups() [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore() [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [test.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [test.csproj]


❯ dotnet build
  Determining projects to restore...
test.csproj : error NU1010: The PackageReference items Microsoft.AspNetCore.Mvc.Testing do not have corresponding PackageVersion.
  Failed to restore test.csproj (in 38 ms).
  39 of 40 projects are up-to-date for restore.

Build FAILED.

test.csproj : error NU1010: The PackageReference items Microsoft.AspNetCore.Mvc.Testing do not have corresponding PackageVersion.
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.32

@tmacam
Copy link

tmacam commented Sep 18, 2024

Finding a similar issue. Building the project from the CLI with dotnet build succeeds but building the project from Visual Studio produces the following error:

Severity	Code	Description	Project	File	Line	Suppression State
Error (active)	MSB4018	The "ResolvePackageAssets" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.NET.Build.Tasks.LockFileExtensions.<GetProjectFileDependencySet>g__IndexOfWhiteSpace|6_1(String s)
   at Microsoft.NET.Build.Tasks.LockFileExtensions.GetProjectFileDependencySet(LockFile lockFile, String frameworkAlias)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.<WritePackageDependenciesDesignTime>g__GetPackageDependencies|59_0()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WritePackageDependenciesDesignTime()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroup(Action writeItems)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.Write()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteToCacheFile()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	Microsoft.ContainerApps.FunctionApp.DurableAsyncOperations	C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets	266	

I notice that my stack trace is slightly different than the one in the main comment as, among other things, it does not mention a ctor.

@hamarb123
Copy link

hamarb123 commented Sep 20, 2024

I'm getting this attempting to compile roslyn on command-line for about 9 of the projects:

C:\Path\To\Roslyn\.dotnet\sdk\9.0.100-preview.7.24407.12\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: (repeated at start of every line, ommited for clarity)
The "ResolvePackageAssets" task failed unexpectedly. [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
System.NullReferenceException: Object reference not set to an instance of an object. [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.ProjectContext.<>c__DisplayClass31_0.<GetTopLevelDependencies>b__3(String projectFileDependency) [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext() [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source) [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.ProjectContext.GetTopLevelDependencies(LockFile lockFile, LockFileTarget lockFileTarget) [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.ComputePackageExclusions() [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task) [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash) [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task) [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups() [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore() [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.NET.Build.Tasks.TaskBase.Execute() [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Path\To\Roslyn\src\VisualStudio\IntegrationTest\TestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.csproj]

Edit: I've saved the state of the VM as a snapshot, so theoretically I should be able to load up that version and repro it later if needed.
Edit 2: doesn't reproduce anymore when I change to rc 1 in the global.json.

@lsoft
Copy link

lsoft commented Sep 27, 2024

any plans here? I face it constantly, a lot of times every day... This is something very painful.

@baronfel
Copy link
Member

@lsoft what version of VS and the SDK are you using? We think this should be resolved in more recent versions of the SDK.

@abatishchev
Copy link

I hit the issue when was migrating an .msbuildproject to CPM:

The "ResolvePackageAssets" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.NET.Build.Tasks.LockFileExtensions.<GetProjectFileDependencySet>g__IndexOfWhiteSpace|6_1(String s)
   at Microsoft.NET.Build.Tasks.LockFileExtensions.GetProjectFileDependencySet(LockFile lockFile, String frameworkAlias)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.<WritePackageDependenciesDesignTime>g__GetPackageDependencies|59_0()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WritePackageDependenciesDesignTime()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroup(Action writeItems)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.Write()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteToCacheFile()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	TypeSpec	C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets	266

@lsoft
Copy link

lsoft commented Sep 27, 2024

@baronfel

Microsoft Visual Studio Enterprise 2022 (64-bit) - Current
Version 17.11.4

C:\Users\ls>dotnet --list-sdks
2.1.818 [C:\Program Files\dotnet\sdk]
3.1.201 [C:\Program Files\dotnet\sdk]
3.1.417 [C:\Program Files\dotnet\sdk]
5.0.302 [C:\Program Files\dotnet\sdk]
5.0.405 [C:\Program Files\dotnet\sdk]
5.0.416 [C:\Program Files\dotnet\sdk]
6.0.101 [C:\Program Files\dotnet\sdk]
6.0.407 [C:\Program Files\dotnet\sdk]
8.0.400 [C:\Program Files\dotnet\sdk]

csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-android</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>disable</ImplicitUsings>
  </PropertyGroup>
</Project>

minimal build log:

20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly.
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ProjectContext.<>c__DisplayClass31_0.<GetTopLevelDependencies>b__3(String projectFileDependency)
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.ComputePackageExclusions()
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
20:57:16:565	1>C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
20:57:16:565	1>Done building project "REMOVED.csproj" -- FAILED.
20:57:16:582	========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

@AdriaanLarcai
Copy link

This is ridiculous.

@lsoft
Copy link

lsoft commented Oct 7, 2024

I see the same issue with the latest SDK

16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly.
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ProjectContext.<>c__DisplayClass31_0.<GetTopLevelDependencies>b__3(String projectFileDependency)
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.ComputePackageExclusions()
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
16:01:59:141	1>C:\Program Files\dotnet\sdk\8.0.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

as I posted above, I politely ask about plans here?

@lsoft
Copy link

lsoft commented Oct 7, 2024

Because I see the error constantly, how can I reproduce this with the sources of SDK inside a Visual Studio?

@lsoft
Copy link

lsoft commented Oct 7, 2024

after digging a bit, I can confirm that the root of problem is in restoring nuget packages.

if I run dotnet restore of the csproj then everything is good and project.assets.json contains normal centralPackageVersions node, and framework/.../dependencies has correct version nodes for example "version": "[8.0.0, )".

but if I delete obj folder, and press rebuild in visual studio, I see that project.assets.json DOES NOT contains normal centralPackageVersions node, and framework/.../dependencies nodes has EMPTY version: "version": "(, )".

Looks like building inside VS (via msbuild?) do not see the versions from Directory.Packages.props for some reason I can't investigate.

ADDITIONAL NOTE: I have a few nuget packages deploed in my Directory.Build.props in addition for those who are deployed in the csproj.

@PaulVrugt
Copy link

PaulVrugt commented Oct 8, 2024

so, is there a way to get rid of the error? I did "something" to get this error, but now it won't go away anymore

edit; ok never mind, in my case it was caused by a package reference for which no version was specified in my Directory.Packages.Props file

@olivier-spinelli
Copy link

This just occured on the up to date Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.11.5.
This is more than annoying...

@divega
Copy link

divega commented Oct 10, 2024

so, is there a way to get rid of the error? I did "something" to get this error, but now it won't go away anymore

edit; ok never mind, in my case it was caused by a package reference for which no version was specified in my Directory.Packages.Props file

Thank you @PaulVrugt. This was helpful! Doing the restore in the command line reported which package it was. Not sure why in VS the restore is crashing.

@marcpopMSFT marcpopMSFT added the needs team triage Requires a full team discussion label Nov 6, 2024
@marcpopMSFT
Copy link
Member

@jeffkl did NuGet end up looking into providing a better error experience here or should we? I believe this is a case of null values in the project.assets.json most commonly when onboarding to CPM and not setting a version for everything.

@jeffkl
Copy link
Contributor

jeffkl commented Nov 12, 2024

I believe we fixed NuGet so it won't write null values but I would expect the SDK to still have some safeguards in case the assets file ends up being written differently? I would certainly hope if NuGet changes the schema in anyway that we don't break this component, but it might be worth having code in the SDK that gives a better error as well.

@Phlow2001
Copy link

This was indeed caused by a null in project.assets.json. The null was caused, presumably, by a removed PackageVersion in a central package management Directory.Packages.props but having a PackageReference still looking for it at the .csproj level. It seems like this can happen easily with multiple solutions and dependants on central package management.

This could absolutely use a better error message.

@marcpopMSFT marcpopMSFT added this to the Backlog milestone Nov 19, 2024
@marcpopMSFT marcpopMSFT removed untriaged Request triage from a team member needs team triage Requires a full team discussion labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests