Skip to content

Latest commit

 

History

History
58 lines (46 loc) · 2.66 KB

File metadata and controls

58 lines (46 loc) · 2.66 KB
title MSB4018 diagnostic code
description Learn about the possible causes of the MSB4018 build error and get troubleshooting tips.
ms.date 05/16/2025
ms.topic error-reference
f1_keywords
MSB4018
MSBuild.FatalTaskError
dev_langs
VB
CSharp
C++
FSharp
author ghogen
ms.author ghogen
ms.subservice msbuild

MSB4018 diagnostic code

This article describes the MSB4018 error code.

Message text

MSB4018: The 'value' task failed unexpectedly.

Description

This error is emitted when a task fails with an unhandled exception. This issue is generally a sign of a bug in the task.

You might encounter this error when the build runs a task in an environment for which it wasn't prepared. For example, when a task has an x86 dependency, but the task runs in a 64-bit MSBuild environment. This scenario can manifest as a System.DllNotFoundException exception, as shown in the following output:

S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018: The "AnyCPUTaskWithPInvoke" task failed unexpectedly.
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018: System.DllNotFoundException: Unable to load DLL 'Native32BitLibrary.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at AnyCPUTaskWithPInvoke.AnyCPUTaskWithPInvoke.NativeMethod()
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at AnyCPUTaskWithPInvoke.AnyCPUTaskWithPInvoke.OtherMethod() in S:\BitnessInMSBuild\AnyCPUTaskWithPInvoke\AnyCPUTaskWithPInvoke.cs:line 19
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at AnyCPUTaskWithPInvoke.AnyCPUTaskWithPInvoke.Execute() in S:\BitnessInMSBuild\AnyCPUTaskWithPInvoke\AnyCPUTaskWithPInvoke.cs:line 12
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Resolution

Ensure the task expresses a dependency on the runtime environment that it requires in the task's UsingTask element.

Applies to

All versions of MSBuild