runtime: HostWriter: ResourceUpdate fails non-deterministically

Steps to reproduce

  1. Create a new web app: dotnet new webapp
  2. 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

Most upvoted comments

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:

  • Create an ASP .Net Core project
  • Compile Solution
  • Clean Solution
  • Execute Solution

Result: MSB4018 Unexpected error in the “CreateAppHost” task. Microsoft.NET.HostModel.HResultException: 8007006E


NET Core SDK (mirroring any global .json):

  • Version: 3.1.100
  • Commit: cd82f021f4

Runtime environment:

  • OS Name: Windows
  • OS Version: 10.0.17134
  • OS Platform: Windows
  • RID: win10-x64
  • Base Path: C: Program Files Dotnet 3.1.100

Last comment:

  • This problem only occurs in projects created in a business environment. (Work)
  • This problem cannot be replicated in a Domestic environment. (Home)

I also see the error in Visual Studio 2019 16.3.1 (3.0.100 SDK) when doing Batch Build -> Select All -> Rebuild:

C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018: The "CreateAppHost" task failed unexpectedly.
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018: Microsoft.NET.HostModel.HResultException: 80070005
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.ResourceUpdater.Update()
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>g__UpdateResources|1()
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.RetryUtil.RetryOnWin32Error(Action func)
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

The solution I’m building is made up of three projects:

  • NET Standard 2.1 library
  • NET Core 3.0 WPF library (references NET Standard 2.1 library)
  • NET Core 3.0 WPF application (references both libraries)

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, sometimes Release, and sometimes both.

I also tried disabling parallel builds by setting the maximum parallel builds in Tools -> Options -> Projects and Solutions -> Build and Run to 1 instead of 12, 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:

1>------ Rebuild All started: Project: TechmemeRiver, Configuration: Release Any CPU ------
1>You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
1>
1>Bundler: Cleaning output from bundleconfig.json
1>Bundler: Done cleaning output file from bundleconfig.json
1>
1>Bundler: Begin processing bundleconfig.json
1>	Minified wwwroot/css/site.min.css
1>	Minified wwwroot/js/site.min.js
1>Bundler: Done processing bundleconfig.json
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018: The "CreateAppHost" task failed unexpectedly.
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018: Microsoft.NET.HostModel.ResourceUpdater+HResultException: 80070005
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.NET.HostModel.ResourceUpdater.Update()
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 35
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 47
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
1>Done building project "TechmemeRiver.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Edit 1:

After doing a “Clean” and “Rebuild”, the error does not occur anymore:

1>------ Rebuild All started: Project: TechmemeRiver, Configuration: Release Any CPU ------
1>You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
1>
1>Bundler: Cleaning output from bundleconfig.json
1>Bundler: Done cleaning output file from bundleconfig.json
1>
1>Bundler: Begin processing bundleconfig.json
1>	Minified wwwroot/css/site.min.css
1>	Minified wwwroot/js/site.min.js
1>Bundler: Done processing bundleconfig.json
1>TechmemeRiver -> E:\Dropbox\Beruf\Prog\TechmemeRiver\Source\TechmemeRiver\bin\Release\netcoreapp3.0\TechmemeRiver.dll
1>TechmemeRiver -> E:\Dropbox\Beruf\Prog\TechmemeRiver\Source\TechmemeRiver\bin\Release\netcoreapp3.0\TechmemeRiver.Views.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

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:

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.<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()	<project name>	C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets	393	

And here is what I see in the Output window:

2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018: Microsoft.NET.HostModel.HResultException: 8007006E
2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018:    at Microsoft.NET.HostModel.ResourceUpdater.Update()
2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>g__UpdateResources|1()
2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018:    at Microsoft.NET.HostModel.RetryUtil.RetryOnWin32Error(Action func)
2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)
2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
2>C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(393,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

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.

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()```

I am building again and hope it works. Please keep us posted on this issue. 

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 targets netcoreapp3.0. I noticed that changing the target framework to netcoreapp2.1, building the project, and then moving back to netcoreapp3.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

λ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.100-preview2-014569
 Commit:    4bd5d24d87

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.100-preview2-014569\

Host (useful for support):
  Version: 3.1.0-preview2.19525.6
  Commit:  5672978d91

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.503 [C:\Program Files\dotnet\sdk]
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.1.507 [C:\Program Files\dotnet\sdk]
  2.1.508 [C:\Program Files\dotnet\sdk]
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.701 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.2.203 [C:\Program Files\dotnet\sdk]
  2.2.204 [C:\Program Files\dotnet\sdk]
  2.2.300 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.100-preview2-014569 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  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.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  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.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.4 [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 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0-preview2.19528.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.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.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.4 [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 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0-preview2.19525.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.0-preview2.19525.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Edit 1

I found out what was causing the exception in my case. In my .csproj I was using the PreBuildEvent feature (you can find out more here). In details, I check if the appsettings.json file exists. If not the script will copy it from example.appsettings.json file.

    <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
        <Exec Command="if NOT exist &quot;$(ProjectDir)appsettings.json&quot; (copy &quot;$(ProjectDir)example.appsettings.json&quot; &quot;$(ProjectDir)appsettings.json&quot;)" />
    </Target>

Commenting out these elements in the .csproj file, the build always succeeds. By the way, while using that feature the appsettings.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

fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018: System.IO.IOException: Invalid argument [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at System.IO.MemoryMappedFiles.MemoryMappedView.CreateView(SafeMemoryMappedFileHandle memMappedFileHandle, MemoryMappedFileAccess access, Int64 requestedOffset, Int64 requestedSize) [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor(Int64 offset, Int64 size, MemoryMappedFileAccess access) [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>g__RewriteAppHost|0() [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at Microsoft.NET.HostModel.RetryUtil.RetryOnIOError(Action func) [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom) [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/src/JobApi.fsproj]
fs_1  | /usr/share/dotnet/sdk/3.1.100-preview1-014459/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(388,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/src/JobApi.fsproj]
build-dist_fs_1 exited with code 1

@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.

I know this issue has been closed // a fix is planned. I just want to chip in and let others know that thanks to @robkuz I realized that in my case it was caused by Synology Drive. I recommend others having this issue to check if anything is syncing the directory to some external file service like Dropbox, Google Drive or a NAS.

Thanks all, this resolved my issues 😄

Is there a date when this will be released.

@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:

  • Copy the template, and update
  • Create Apphost, write bundle contents

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:

|- .git
|- src
     |- projectdir
     |- project.sln

@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.