Skip to content

[Unhandled Exception]: ArgumentNullException "Parameter "projectFile" cannot be null" in ctor of InvalidProjectFileException #12723

@PhilippNaused

Description

@PhilippNaused

Issue Description

Found this issue when I tried to use the new https://aka.ms/nettaskhost feature in VS2026 Insiders (11201.2):

I got this error:

Launching task "Task1" from assembly "E:\ws\Test2\publish\Test.dll" in an external task host with a runtime of "NET" and a process architecture of "x64". (TaskId:2)
MSBUILD : error : The task failed to load because it requires the MSBuild .NET Runtime Task Host, but the .NET Runtime Task Host could not be found for the specified version. [E:\ws\Test2\Test.proj]
MSBUILD : error :     See https://aka.ms/nettaskhost for details on how to resolve this error. [E:\ws\Test2\Test.proj]

However, I can only see this error when I specify ContinueOnError="true" on my task.
If I don't, MSBuild terminates with an unhandled exception: System.ArgumentNullException: Parameter "projectFile" cannot be null.

Steps to Reproduce

test.binlog

Minimal project (4 files) that repos the issue:
Code.zip
Just run Test.ps1 from "Developer PowerShell for VS 18"

Actual Behavior

MSBUILD : error : This is an unhandled exception in MSBuild -- PLEASE UPVOTE AN EXISTING ISSUE OR FILE A NEW ONE AT https://aka.ms/msbuild/unhandled [E:\ws\Test2\Test.proj]
MSBUILD : error :     System.ArgumentNullException: Parameter "projectFile" cannot be null. [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.Shared.ErrorUtilities.ThrowArgumentNull(String parameterName, String resourceName) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.Exceptions.InvalidProjectFileException..ctor(String projectFile, Int32 lineNumber, Int32 columnNumber, Int32 endLineNumber, Int32 endColumnNumber, String message, String errorSubcategory, String errorCode, String helpKeyword, Exception innerException) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.Exceptions.InvalidProjectFileException..ctor(String message, InvalidProjectFileException innerException) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.<InitializeAndExecuteTask>d__24.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteBucket>d__19.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteTask>d__18.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteTask>d__13.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TargetEntry.<ProcessBucket>d__50.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TargetEntry.<ExecuteTarget>d__43.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TargetBuilder.<ProcessTargetStack>d__24.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.TargetBuilder.<BuildTargets>d__11.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.RequestBuilder.<BuildProject>d__67.MoveNext() [E:\ws\Test2\Test.proj]
MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [E:\ws\Test2\Test.proj]
MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [E:\ws\Test2\Test.proj]
MSBUILD : error :    at Microsoft.Build.BackEnd.RequestBuilder.<RequestThreadProc>d__58.MoveNext() [E:\ws\Test2\Test.proj]

Analysis

In this line:

throw new InvalidProjectFileException(ipex.Message, ipex);

A InvalidProjectFileException is wrapped in another InvalidProjectFileException.
The ctor passes the property ProjectFile as the projectFile argument:
internal InvalidProjectFileException(string message, InvalidProjectFileException innerException)
: this(innerException.ProjectFile, innerException.LineNumber, innerException.ColumnNumber, innerException.EndLineNumber, innerException.EndColumnNumber, message, innerException.ErrorSubcategory, innerException.ErrorCode, innerException.HelpKeyword)

The inner ctor throws if projectFile is null despite the fact that the ProjectFile property can (and is) null.
The xml docs explicitly say that it can be null:
/// <value>Project filename/path string, or null.</value>
public string ProjectFile

The exception seems to originate here:

throw new InvalidProjectFileException(ResourceUtilities.GetResourceString("NETHostTaskLoad_Failed"));

where is was created without a value for projectFile.

Versions & Configurations

msbuild -version:
MSBuild version 18.0.2+995a3dce4 for .NET Framework
18.0.2.52102

dotnet --info:

<details>
.NET SDK:
 Version:           10.0.100-rc.2.25502.107
 Commit:            89c8f6a112
 Workload version:  10.0.100-manifests.4d32cd9e
 MSBuild version:   18.0.0-preview-25502-107+89c8f6a11

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26200
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.100-rc.2.25502.107\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
  Version:      10.0.0-rc.2.25502.107
  Architecture: x64
  Commit:       89c8f6a112

.NET SDKs installed:
  8.0.415 [C:\Program Files\dotnet\sdk]
  9.0.306 [C:\Program Files\dotnet\sdk]
  10.0.100-rc.2.25502.107 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.0-rc.2.25502.107 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.0-rc.2.25502.107 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.0-rc.2.25502.107 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions