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

Randomly get 'The "CreateAppHost" task failed unexpectedly' error when doing CLI build of a new web app #3831

Closed
wli3 opened this issue Nov 5, 2019 · 66 comments
Assignees
Labels
area-HostModel Microsoft.NET.HostModel issues
Milestone

Comments

@wli3
Copy link

wli3 commented Nov 5, 2019

From @DamianEdwards on Thursday, June 27, 2019 7:48:16 PM

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

Copied from original issue: dotnet/cli#11650

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @livarcocc on Thursday, June 27, 2019 7:50:20 PM

@peterhuene can you take a look?

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @peterhuene on Thursday, June 27, 2019 7:52:13 PM

0x8007006E is cannot open the file specified. Not entirely sure if that's because it doesn't exist or a sharing violation. My guess would be on the latter since it's intermittent (perhaps something external to the build is interfering?).

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @peterhuene on Thursday, June 27, 2019 7:53:35 PM

We have a lot of tests that create and customize the apphost on Windows and I haven't seen flaky CI with this. I'll attempt to repro it.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @livarcocc on Thursday, June 27, 2019 7:57:45 PM

Anti-virus?

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @peterhuene on Thursday, June 27, 2019 10:00:29 PM

I ran dotnet build 100 times in my VM with 3.0.100-preview7-012687 and had no failures.

@DamianEdwards are you seeing this on a particular machine or multiple machines?

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @DamianEdwards on Friday, June 28, 2019 8:12:37 PM

@peterhuene was seeing this on only one machine so far, but haven't tried to repro it on my other machine.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @peterhuene on Monday, July 15, 2019 10:52:15 PM

@DamianEdwards I'm still not able to reproduce this.

The API call is EndUpdateResource and the error code is 110 (ERROR_OPEN_FAILED). It seems that some antivirus software may interfere with this API.

As I don't have any MSIT-controlled Windows machines (and it's been a decade since I last did), I don't know what we're using for antivirus on corpnet these days.

Would it be possible to check if its the real-time protection of the antivirus software that's interfering with the build?

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @peterhuene on Friday, July 26, 2019 7:22:42 PM

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.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @wli3 on Thursday, August 1, 2019 10:17:07 PM

I have a repro too during app building on blazor server app, but not consistent. I ran git clean -fxd. and open the sln with VS then F5.

Severity	Code	Description	Project	File	Line	Suppression State
Error	MSB4018	The "CreateAppHost" task failed unexpectedly.
System.IO.IOException: The process cannot access the file 'C:\work\appbuilding\emojisearch.blazor\emojisearch.blazor\obj\Debug\netcoreapp3.0\emojisearch.blazor.exe' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
   at System.IO.File.OpenFile(String path, FileAccess access, SafeFileHandle& handle)
   at System.IO.File.SetLastWriteTimeUtc(String path, DateTime lastWriteTimeUtc)
   at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)
   at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 35
   at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 47
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	emojisearch.blazor	C:\Program Files\dotnet\sdk\3.0.100-preview9-013654\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets	359	

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @peterhuene on Thursday, August 1, 2019 10:27:04 PM

Would it be possible to use procmon to see if we can figure out who is opening the file? I've never been able to reproduce the issue in a VM.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @wli3 on Thursday, August 1, 2019 10:40:45 PM

good point, let me try several times more

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @peterhuene on Tuesday, August 6, 2019 6:31:04 PM

For preview 9, we'll retry the apphost creation as a mitigation for these file locking issues.

I'm going to leave this issue open for now to see if we can get some idea of which external process is locking the apphost.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @wli3 on Wednesday, August 7, 2019 6:36:16 PM

Spend another half of an hour trying to repro, see once again, but forget to open procmon :( start to think it is anti virus scan -- once it is scanned once, it no longer does that anymore.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @swaroop-sridhar on Saturday, August 10, 2019 12:12:58 AM

@peterhuene I looked a bit more at the ResourceUpdater code in HostModel -- wrt whether/where retries should be added to ResouceUpdater code.

Looks like there are only two places where a file is opened:

Both the above functions take in a path and obtain a HANDLE to it. So, it is reasonable that we have retries around these calls to protect against an AV locking the apphost file. The remaining functions operate on the handles obtained above, which should have secured the file open for use. So, we should not need retries around them.

In particular, in the callstack described above, we see that the Kernel32.EndUpdateResource() failed on a previously open apphost -- after we've checked that the handle is non-zero.

So, I don't think adding retries is the correct fix in this case.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @swaroop-sridhar on Saturday, August 10, 2019 12:26:21 AM

There is one scenario I can see where we may end up in this case: If we call ResourceUpdater.Update() twice.

The Update() function releases the SafeHandle whether or not it succeeds, but it does not zero out the handle. So, it is possible that we have a stale handle that passes the SafeUpdateHandle.IsInvalid test, but then ends up throwing the error.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @swaroop-sridhar on Saturday, August 10, 2019 1:03:43 AM

The error codes for lock-violation is 21 (file) and 6C (disk).
The 6E error code is for a file that cannot be open (which agrees with the theory that the handle is invalid).

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @swaroop-sridhar on Saturday, August 10, 2019 2:41:53 AM

@peterhuene @wli3
I've submitted dotnet/core-setup#7665 for retrying resource-update in HostModel. But I don't think it'll fix this issue.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @nguerrera on Monday, August 12, 2019 6:52:45 PM

Reopened based on discussion above suggesting there's still something else here

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @UweKeim on Thursday, August 22, 2019 1:32:33 PM

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.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @livarcocc on Thursday, August 22, 2019 5:39:08 PM

@peterhuene any ideas?

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @peterhuene on Thursday, August 22, 2019 7:27:08 PM

No new theories other than something like an antivirus program is interfering with writing out the resources. I've been unable to reproduce at all, but I don't use any such programs that might interfere in this manner.

The above is a generic access denied error. I still believe that retry at the point of resource updater interaction in HostWriter will help mitigate the issue.

Ultimately I hope a future version of the SDK opens the apphost just once for customization, but that would require getting rid of the resource API usage (something we want to do to increase supported platforms for the operation anyway).

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @Kurira on Saturday, September 28, 2019 6:15:41 AM

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.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @charsleysa on Sunday, September 29, 2019 5:53:02 AM

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

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @wli3 on Sunday, September 29, 2019 8:17:56 PM

@charsleysa i'll continue work on this issue.

Are you using the 3.0.100 SDK?

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @charsleysa on Sunday, September 29, 2019 9:07:40 PM

@wli3 yes, I'm using the 3.0.100 SDK that is installed alongside Visual Studio 2019 16.3.1

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @SirUppyPancakes on Tuesday, October 1, 2019 7:16:41 AM

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.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @TEnigma on Wednesday, October 2, 2019 9:37:09 AM

I just had the same thing on our buildserver (Windows Server 2016) with SDK 3.0.100 and I think for us the problem was that the path of the generated files are to long. Can it be?

But I had other HResultException: 8007007A

I copied the folder to a shorter path and then the build worked.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @ooXei1sh on Sunday, October 6, 2019 4:12:13 AM

Similar exception seen using VSCode with dotnet watch run command in windows 10 linux subsystem terminal:
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.

Closing and reopening VSCode would fixed temporarily.
Just Disconnecting from WSL Ubuntu within VSCode seems to have solved it.

Disconnecting from WSL Ubuntu from VSCode menu on bottom left of UI.
WSL: Ubuntu > Close Remote Connection

Maybe related ticket, but just moving to ~ path didn't work for me: dotnet/core#3444

After disconnecting WSL: Ubuntu remote connection, dotnet watch run command works as expected, changing .cs files no longer results in build failures while watching. Seems like a non issue for me now.

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @conkman on Thursday, October 10, 2019 12:29:28 PM

I am also running into this on our Dotnet core 2.2 project. It is very intermittent. Has a root cause been found yet?

@wli3
Copy link
Author

wli3 commented Nov 5, 2019

From @garethblz on Monday, October 28, 2019 6:27:28 PM

I also reproduced the issue on netcoreapp 3.0.100 in Visual Studio 2019 16.3.9. Simple ASP.NET Core project on the IIS Express profile. The only external dependencies are on StyleCop.Analyzers 1.1.118. Would be interested to know if anyone else experienced this with the same dependencies. Here's the error (looks the same as what's reported).

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

@swaroop-sridhar swaroop-sridhar self-assigned this Nov 5, 2019
@swaroop-sridhar
Copy link
Contributor

https://github.com/dotnet/sdk/issues/3863 was transferred to core-setup as https://github.com/dotnet/core-setup/issues/8776.

So we no longer need this issue.

@nightroman
Copy link

Is it just me or all these issues are closed now? One should be still open, right?

@swaroop-sridhar
Copy link
Contributor

swaroop-sridhar commented Nov 5, 2019

@nightroman dotnet/core-setup#8776 is open .. sorry for the confusion with the two issues.

@baoshenyi
Copy link

I got same issue with "Clean" and "Rebuild", it worked fine. but it is very annoying.
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

@baoshenyi
Copy link

what is this file (C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets) for? BTW, I use .net core 3.0 to build my asp.net core app not 3.1.1. In case, it helps.

@wli3
Copy link
Author

wli3 commented Dec 4, 2019

@baoshenyi could you comment on https://github.com/dotnet/core-setup/issues/8776

this issue is moved to that one

@fitimdurmishi
Copy link

In my case, the issue is fixed if i switch to Release, on Debug is still happening :(

@tomasr78
Copy link

I get the same exception while building Web Project. Any fix?

@msftgits msftgits transferred this issue from dotnet/core-setup Jan 30, 2020
@msftgits msftgits added this to the 5.0 milestone Jan 30, 2020
@ghbeta
Copy link

ghbeta commented Feb 6, 2020

i also get this exception with .net core 3.1. it stops the whole CI

@wli3
Copy link
Author

wli3 commented Feb 6, 2020

@fitimdurmishi @tomasr78 @ghbeta could you comment on https://github.com/dotnet/core-setup/issues/8776 ? This thread is no monitored

@Gladskih
Copy link

@wli3 You better monitor this thread as it's the first position in google on "createapphost task failed unexpectedly".

@mtwarowski
Copy link

I've just did File->New Project -> WebApi in visual studion 2019 with .net core 3.1. and got the same error.

It went away after Clean and Rebuild but it's not a great experience :(

@kknd4eva
Copy link

I've encountered this same issue doing a build on a .NET Core Worker Service with Docker compatibility in VS2019 on Windows 10. Error below:

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

@kknd4eva
Copy link

Seems mine is not so much random, as every time I try to build :/ I don't know how to fix it.

@kknd4eva
Copy link

I just turned off Windows anti-virus real time protection, did a build again - this time no error. So whoever mentioned Anti Virus earlier in this thread is probably onto something.

@danmoseley
Copy link
Member

Locking to direct new posts to #3832

@dotnet dotnet locked and limited conversation to collaborators Mar 30, 2020
@dotnet dotnet unlocked this conversation Mar 30, 2020
@danmoseley
Copy link
Member

That's closed too. @wli3 is there an active issue here?

@wli3
Copy link
Author

wli3 commented Mar 30, 2020

@danmosemsft i think #3832 should be the right one. It is closed due to fix is merged. @swaroop-sridhar

@danmoseley
Copy link
Member

OK. I am still going to lock this in order to send any new comments there.

@dotnet dotnet locked and limited conversation to collaborators Mar 30, 2020
@swaroop-sridhar
Copy link
Contributor

This fix is expected to be in release 3.1.4 later this month.
#34950 (comment)

@swaroop-sridhar
Copy link
Contributor

#34950

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-HostModel Microsoft.NET.HostModel issues
Projects
None yet
Development

No branches or pull requests