runtime: HostWriter: ResourceUpdate fails non-deterministically
Steps to reproduce
- Create a new web app:
dotnet new webapp
- Repeatedly build the app from the CLI with no changes:
dotnet build
Expected behavior
No errors
Actual behavior
Randomly see the following error (twice in the last 20 builds just now):
C:\src\local\BuildPerf\WebApp3.0> dotnet build Microsoft (R) Build Engine version 16.3.0-preview-19325-02+eca7818b1 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 19.81 ms for C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj.
You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: Microsoft.NET.Build.Tasks.ResourceUpdater+HResultException: 8007006E [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResourceUpdater.ThrowExceptionForLastWin32Error() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResourceUpdater.cs:line 436 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResourceUpdater.Update() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResourceUpdater.cs:line 324 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.AppHost.Create(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String intermediateAssembly, Logger log) in /_/src/Tasks/Microsoft.NET.Build.Tasks/AppHost.cs:line 82 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 38 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 38 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
Build FAILED.
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: Microsoft.NET.Build.Tasks.ResourceUpdater+HResultException: 8007006E [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResourceUpdater.ThrowExceptionForLastWin32Error() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResourceUpdater.cs:line 436 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResourceUpdater.Update() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResourceUpdater.cs:line 324 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.AppHost.Create(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String intermediateAssembly, Logger log) in /_/src/Tasks/Microsoft.NET.Build.Tasks/AppHost.cs:line 82 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 38 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 38 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:02.58
Environment data
dotnet --info
output:
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview7-012649
Commit: 3f4ab7f5c5
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\
Host (useful for support):
Version: 3.0.0-preview7-27826-04
Commit: 5c4d829254
.NET Core SDKs installed:
2.1.700-preview-009618 [C:\Program Files\dotnet\sdk]
2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
2.2.204 [C:\Program Files\dotnet\sdk]
3.0.100-preview7-012649 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview7.19326.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview7-27826-04 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview7-27826-04 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 12
- Comments: 82 (28 by maintainers)
Commits related to this issue
- Retry apphost creation. This commit implements a parameterized retry count for creating the apphost. Like the `Copy` task from MSBuild, the `CreateAppHost` task now takes a parameter to specify the ... — committed to peterhuene/sdk by deleted user 5 years ago
- Retry apphost creation. This commit implements a parameterized retry count for creating the apphost. Like the `Copy` task from MSBuild, the `CreateAppHost` task now takes a parameter to specify the ... — committed to peterhuene/sdk by deleted user 5 years ago
- Retry apphost creation. This commit implements a parameterized retry count for creating the apphost. Like the `Copy` task from MSBuild, the `CreateAppHost` task now takes a parameter to specify the ... — committed to peterhuene/sdk by deleted user 5 years ago
- Retry apphost creation. This commit implements a parameterized retry count for creating the apphost. Like the `Copy` task from MSBuild, the `CreateAppHost` task now takes a parameter to specify the ... — committed to peterhuene/sdk by deleted user 5 years ago
- HostModel: Retry ResourceUpdate on Win32 error This change attempts to fix a non-detereministic customer reported failure. Several customers have observed failure during resource update when the Hos... — committed to swaroop-sridhar/runtime by swaroop-sridhar 4 years ago
- HostModel: Retry ResourceUpdate on Win32 error This change attempts to fix a non-deterministic customer reported failure. Several customers have observed failure during resource update when the Host... — committed to swaroop-sridhar/runtime by swaroop-sridhar 4 years ago
- HostModel: Retry ResourceUpdate on Win32 error This change attempts to fix a non-deterministic customer reported failure. Several customers have observed failure during resource update when the Host... — committed to swaroop-sridhar/runtime by swaroop-sridhar 4 years ago
- HostModel: Retry ResourceUpdate on Win32 error (#32347) This change attempts to fix a non-deterministic customer reported failure. Several customers have observed failure during resource update wh... — committed to dotnet/runtime by swaroop-sridhar 4 years ago
- [release/3.1] HostModel: Retry ResourceUpdate on Win32 error https://github.com/dotnet/runtime/issues/3832 Building a WinExe with resources fails non-deterministically Several customers have observ... — committed to swaroop-sridhar/core-setup by swaroop-sridhar 4 years ago
- [release/3.1] HostModel: Retry ResourceUpdate on Win32 error https://github.com/dotnet/runtime/issues/3832 Building a WinExe with resources fails non-deterministically Several customers have observ... — committed to swaroop-sridhar/core-setup by swaroop-sridhar 4 years ago
- [release/3.1] HostModel: Retry ResourceUpdate on Win32 error (#9012) https://github.com/dotnet/runtime/issues/3832 Building a WinExe with resources fails non-deterministically Several customers... — committed to dotnet/core-setup by swaroop-sridhar 4 years ago
This still happens randomly on release bits. Usually on build either through vs or if dotnet tool tries to compile assembly. Never happened twice in a row though.
I hope this will be prioritized before .NET 5.0 as the current milestone indicates. It might not be breaking, but it is quite annoying to to a clean and built.
Error MSB4018 The “CreateAppHost” task failed unexpectedly. Microsoft.NET.HostModel.HResultException: 80070005 at Microsoft.NET.HostModel.ResourceUpdater.Update() at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>g__UpdateResources|1() at Microsoft.NET.HostModel.RetryUtil.RetryOnWin32Error(Action func) at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom) at Microsoft.NET.Build.Tasks.CreateAppHost.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() deliberately.left.out C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets 393
@jberd126 Unfortunately I don’t work on .NET (or at Microsoft) any longer, but I’m sure @nguerrera or @swaroop-sridhar are tracking this issue.
@kalkisama I suspect the issue you’re running into is dotnet/sdk#2989 where creating the apphost doesn’t work on file systems that can’t be mapped as
MAP_SHARED
.@nguerrera Regarding the failure to map the file, I think it would really help if the core-setup folks produced known offsets for the SDK (shouldn’t be too hard to generate an asset containing the offset from their builds). It doesn’t make sense for the SDK to have to scan for the path marker.
Additionally, I think given the number of users running into problems with apphost creation, it should help motivate the adoption of a cross-platform resource writer that would allow the SDK to open the apphost once so that antivirus and other applications can’t sneak in-between the opens and lock the file.
We are experiencing the same problem with .Net 3.0, 3.1 migrated and new solutions.
The worst part is that I can replicate it:
Result: MSB4018 Unexpected error in the “CreateAppHost” task. Microsoft.NET.HostModel.HResultException: 8007006E
NET Core SDK (mirroring any global .json):
Runtime environment:
Last comment:
I also see the error in Visual Studio 2019 16.3.1 (3.0.100 SDK) when doing
Batch Build
->Select All
->Rebuild
:The solution I’m building is made up of three projects:
The error occurs every third or so attempt and only seems to manifest on the NET Core 3.0 WPF Application build (and not on the core libraries). Sometimes it’ll be on the
Debug
configuration, sometimesRelease
, and sometimes both.I also tried disabling parallel builds by setting the maximum parallel builds in
Tools
->Options
->Projects and Solutions
->Build and Run
to1
instead of12
, but the error still occurs every third attempt or so.My computer configuration is also pretty bare bones, running Windows 10 with the latest updates, no major telemetry programs or real-time antivirus running.
I’m getting this/a similar error with an ASP.NET Core 3 Preview-7 project, when I first opened it with Preview-8 in Visual Studio 2019:
Edit 1:
After doing a “Clean” and “Rebuild”, the error does not occur anymore:
I hope, it stays this way.
I’m also experiencing this issue, as is my entire team at work. We’re using VS2019 16.4.2, and dotnetcore 3.1.1. We were also experiencing it on older versions of VS2019 and dotnetcore 3.1 and 3.0. I’ve tried running VS as an administrator, but that didn’t seem to help. I’ve noticed that this only seems to happen at work - I don’t experience this issue on my personal PC at home. My best guess is that the antivirus at work is somehow interfering with the build.
Here is what I get in the Error List window:
And here is what I see in the Output window:
I just upgraded our web app to dotnetcore3.1. We publish it using TeamCity and publish it to Azure. I just received the following message.
I got same issue with “Clean” and “Rebuild”, it worked fine. but it is very annoying.
what is “C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets” for? I used .net core 3.0 instead of 3.1.1 to build my asp.net app.
Severity Code Description Project File Line Suppression State Error MSB4018 The “CreateAppHost” task failed unexpectedly. Microsoft.NET.HostModel.HResultException: 8007006E at Microsoft.NET.HostModel.ResourceUpdater.Update() at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.g__UpdateResources|1() at Microsoft.NET.HostModel.RetryUtil.RetryOnWin32Error(Action func) at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom) at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() at Microsoft.NET.Build.Tasks.TaskBase.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() Acme.BookStore.Web C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets 388
I’m getting this error, too. I receive the error while building a
Microsoft.NET.Sdk.Web
project that targetsnetcoreapp3.0
. I noticed that changing the target framework tonetcoreapp2.1
, building the project, and then moving back tonetcoreapp3.0
seems to fix the issue for a while (a bunch of building).I tried to update to the latest preview available, but I’m still having this issue.
The error occurs from command line, Rider and also Visual Studio
Here my
dotnet --info
Edit 1
I found out what was causing the exception in my case. In my
.csproj
I was using thePreBuildEvent
feature (you can find out more here). In details, I check if theappsettings.json
file exists. If not the script will copy it fromexample.appsettings.json
file.Commenting out these elements in the
.csproj
file, the build always succeeds. By the way, while using that feature theappsettings.json
file was created even if the build failed.Hope this can help finding out where the issue is.
Edit 2
Running Visual Studio Community 2019 (v16.3.1) with Administrator rights seems to temporarily solve the issue.
I agree 100% with @peterhuene. Nice to hear from you.
I’ve filed the following to do both of those things:
https://github.com/dotnet/core-setup/issues/8763 https://github.com/dotnet/core-setup/issues/8764
Having the same problem trying to do a “dotnet publish” inside a 3.1-preview SDK container, which is inside a WSL2 ubuntu, with the source code mapped to a /mnt/c/src/… volume. Yeah, i know… haha
@wli3 yes, I’m using the 3.0.100 SDK that is installed alongside Visual Studio 2019 16.3.1
I’m updating the
CreateAppHost
task to be more resilient to a temporarily locked intermediate apphost, like MSBuild handles file copying. Hopefully this will help alleviate this problem.@robkuz I think this fix will make it into the April servicing release.
Yes it is 500 retries with 100 ms wait between each. So, a real failure will take about a minute to fail.
This is now becoming absurd! I am literally trying to do a deployment for more than 8 hours now and I get this error all the time
@nguerrera I think the above are good issues to solve.
But it may still not be sufficient to address the problem – because the file may be locked in between operations like:
So, we will still need to have retries.
Based on the original bug, we added retries to ResourceUpdate() based for Win32 errors that lock the file or disk. But looks like the failure here is for a different error code. It is "access denied (5) and not file/disk lock (33/108). So, the retry check needs to be expanded to acomodate this error code.
I can confirm the opposite. In the crash I experienced, Git was not present. I built from a “src” folder, which sits a directory below the parent that contains the git directory. Like so:
@peterhuene maybe this has something to do with WSL?
I found that if I have the project folder open in VSCode through WSL (no files open, just the project folder loaded in VSCode) then this error occurs, though I experience this error through Visual Studio not the CLI.
To get around this issue I close VSCode, wait a few seconds, run the compilation, then re-open VSCode. This allows it to compile just fine.