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

The "CreateAppHost" task failed unexpectedly. (Version 16.4.5) #10708

Closed
avifatal opened this issue Feb 24, 2020 · 41 comments
Closed

The "CreateAppHost" task failed unexpectedly. (Version 16.4.5) #10708

avifatal opened this issue Feb 24, 2020 · 41 comments

Comments

@avifatal
Copy link

Hi,

Microsoft Visual Studio Community 2019
Version 16.4.5
Randomly getting the bellow error. I have added my root folder to the antivirus exclusion list.

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

Thanks

@brcaswell
Copy link

brcaswell commented Feb 24, 2020

curious... Are you running multiple VS instances or VS Code. Anything in that manner?

Also, have you tried running Visual Studio in Administrator (ADMIN) mode? "Run as Administrator"

@brcaswell
Copy link

brcaswell commented Feb 24, 2020

Well, it does seem a Win32 File Lock may be the cause.


Apart from the 'why' concern,

// Note: replace this when https://github.com/dotnet/core-setup/issues/7516 is fixed
ex.GetType().Name == "HResultException")

Indicates the exception handling should be replaced once dotnet/core-setup#7665 was merged, is that something that should be done?

is capturing the HResultException keeping this exception from being handled differently? @peterhuene ?

@avifatal
Copy link
Author

avifatal commented Feb 24, 2020

Hi.
It is running as administrator.
Its a multiple startup web projects. Running on docker .

I think only one instance of vs2019 is running.

I use to kill the docker containers to solve this issue.
But since i updated vs 2019 to the latest version this does not help anymore..
Clean rebuild sometime helps but its very very long...

Vs code is running react project in the background from a different folder.
Thanks

@avifatal
Copy link
Author

avifatal commented Feb 26, 2020

@brcaswell Maybe it is not so related to docker or 2 startup projects...
also happening in the test:

image

Actually now, vs has become almost in-usable. I need to clean rebuild almost every debug...

@avifatal
Copy link
Author

avifatal commented Mar 5, 2020

@brcaswell Can you please help with this issue??? I'm dying here...
Thanks

@marekpetak
Copy link

Same here. Using net core 3.1, single or multiple VS instance(s) makes no different, running on localhost:5000. Very random, it happens on rebuild, run and and I've seen it happening on IIS once published. I could run/debug the api for a half a day with no problem, then it happens again.

@avifatal
Copy link
Author

avifatal commented Mar 5, 2020

@marekpetak I think it is starting when you stop and after very very short time debug again. then, after that point, it becomes very random... very hard to work like that

@swaroop-sridhar
Copy link
Contributor

This is a dup of dotnet/runtime#3832.
A fix for this issue was checked into the master branch: dotnet/runtime#32347

This fix is approved for servicing: dotnet/core-setup#9012
It'll be released in an upcoming servicing fix.

@swaroop-sridhar
Copy link
Contributor

swaroop-sridhar commented Mar 5, 2020

CC: @wli3 @nguerrera

@brcaswell
Copy link

brcaswell commented Mar 5, 2020

Indeed. In this scenario, those changes to apply that retry logic should apply. Should fix it

image

@AlbertoBN
Copy link

The problem persists with latest SDK

@ScottHutchinson
Copy link

ScottHutchinson commented Apr 10, 2020

For me, cleaning the solution in VS 2019 16.4.5 and SDK 3.1.101 fixed this build error.
EDIT: Later in the day, it happened again (while I had another VS open), and I had to restart VS to fix it again. The solution files were in my Dropbox folder.

@AlbertoBN
Copy link

For me it happens also in command line. And I love command line.

@jrbriones
Copy link

curious... Are you running multiple VS instances or VS Code. Anything in that manner?

Also, have you tried running Visual Studio in Administrator (ADMIN) mode? "Run as Administrator"

Thank you! i had both things you mentioned going for me, i closed one of the instances (in a different IDE i was trying out) then i ran as admin and it finally worked!

@marekpetak
Copy link

I can almost recreate this problem.

  1. project compile fine
  2. do some changes that will cause it not to compile
  3. fix issue, hit build, it will crash
  4. build again, all fine

repeat and it will always crash first time, on 2nd time OK.

@avifatal
Copy link
Author

This is a nightmare... nothing helps

@roblohmann
Copy link

Running into this issue a lot as wel.. Just running a simple project with 2 docker containers, the docker-compose is my startup and it is the only VS2019 instance running.

What helps me is just to clean to solution, after that I can debug untill it occurs again.

@AlbertoBN
Copy link

Called corporate IT... They added an exception on the antivirus on my dev folder. Problem solved

@stimpy77
Copy link

stimpy77 commented May 7, 2020

That's a workaround, not a resolution, @AlbertoBN . I tried to do the same, but the specific Trend Micro product installed on my machine explicitly doesn't support wildcards on exclusion paths, so I ended up having them completely disable TM. Now I'm stuck without a working antivirus. In the end, a code build process should not be hindered by antivirus. exclusions aside. We can blame the AV vendors, but I don't recall having this problem with any .NET build component in the last 18 years I've been using .NET.

@swaroop-sridhar
Copy link
Contributor

The fix to perform more retries on the AppHost update will be in 3.1.4, scheduled for next week.
Hope this will help alleviate the problem in most cases.

@AlbertoBN
Copy link

That's a workaround, not a resolution, @AlbertoBN . I tried to do the same, but the specific Trend Micro product installed on my machine explicitly doesn't support wildcards on exclusion paths, so I ended up having them completely disable TM. Now I'm stuck without a working antivirus. In the end, a code build process should not be hindered by antivirus. exclusions aside. We can blame the AV vendors, but I don't recall having this problem with any .NET build component in the last 18 years I've been using .NET.

True. It is a workaround... And out of a team of 7 it happens to me only on a brand new laptop. However by the time the next version comes out and by the time we get to install it this is the best option for me.

@Nathaire
Copy link

I had the same issue as well. Moving the solution folder into a folder not checked by the windows antivirus solve the issue.

@salvatorious
Copy link

This is happening on Linux as well, when attempting to run dotnet build for a 3.1.202 application.

@avifatal
Copy link
Author

The fix to perform more retries on the AppHost update will be in 3.1.4, scheduled for next week.
Hope this will help alleviate the problem in most cases.

@swaroop-sridhar the fix is not working.
I have installed 3.1.4 and it is still happening...
Please advise another workaround. our efficiency dropped by 40% because of this...
We have 23 projects in the solution. we need to clean the solution every debug.
it is impossible...
Thanks

@swaroop-sridhar
Copy link
Contributor

@avifatal to confirm:

  • You tried building an app with the new SDK in 3.1.4 release, right?
  • What was the SDK version?
  • Do you see the failure during Microsoft.NET.HostModel.RetryUtil.RetryOnWin32Error() during resource-update?
  • What was the exception?

As for workarounds, you can try disabling interference from other programs from locking the host when the build is in progress -- for example, whitelisting the executable you are building with anti-virus scanners.

@troygerton
Copy link

I just started getting this same issue this afternoon. I have compiled this solution hundreds of times over the past 2 weeks. Additionally, Windows Defender think the output DLL is a Trojan.
Capture
I have deleted the bin and obj dirs in my project. Each time I build the project it fails and windows defender logs a virus. I have done a complete virus scan using windows defender and a couple other tools - my machine is clean.
What is going on?

@troygerton
Copy link

Updated VS to latest release and allowed my dll thru windows defender as a workaround.

@avifatal
Copy link
Author

@swaroop-sridhar ok. no matter what update I made it is still happening. the one thing that helped is updating visual studio to the most recent: 16.6.0
Thanks for helping out.
Avi

@NicolasReyDotNet
Copy link

I got it too

@kaldren
Copy link

kaldren commented Jun 7, 2020

Cleaning the solution fixed this for me.
(Visual Studio 2019 16.6.1)

@NicolasREY69330
Copy link

Solved it upgrading to VS 16.6.0, I never had it again

@chendricks16
Copy link

Sill having this issue, I'm at VS 16.6.2. Any further resolution?

@swaroop-sridhar
Copy link
Contributor

swaroop-sridhar commented Jun 18, 2020

@chendricks16 can you please add a few more details to your failure?

  • What was your solution targetting?
  • Did you do a clean rebuild?
  • Can you make sure you're using the latest SDK (run dotnet --version from the project root)
  • What was the HResult exception code?

@AccsysTTD
Copy link

We had a similar issue and it was due to having simultaneously accessing the working folder in WSL and windows. This seemed to cause a locking problem and exhibited with this error.

@danvln
Copy link

danvln commented Aug 15, 2020

Same here. This issue for me was caused by WSL locking. I had to shutdown WSL completely to have it working, and in addition I observed (not measured) that the speed of VS 2019 is way better with WSL shutdown.

@dinispeixoto
Copy link

dinispeixoto commented Sep 30, 2020

Closing VS Code (running on WSL) solved the issue for me. Also worth mentioning that both VS and VS Code were using the same working dir

@safv12
Copy link

safv12 commented Oct 27, 2020

Closing VS Code (running on WSL) solved the issue for me. Also worth mentioning that both VS and VS Code were using the same working dir

Me too!

@brcaswell
Copy link

Thanks everyone for contributing your scenarios, experience and workarounds to this issue; This particular issue was in the context of 16.4.5 and an earlier dotnetcore SDK. It was (has been) designated to be closed as a duplicate. That duplicate, original issue facilitated work on the retry logic that directly affects the reproducibility of this issue, and has been since released.

Given that OP did indicate the issue was resolved with 16.6.0 version, I wouldn't expect reproducibility by the originator of this issue. As such, I think any subsequent issue and observation should be new on the basis of having the new functionality in place and with reproducibility.

So, If you are experiencing this exception and issue on 16.6.X or later, please create a new issue workitem - feel free to link to this closed issue.

@JoeWiseman
Copy link

Hi there,
I'm on VS 16.8.4 and when opeing and compiling a VB.Net-Windows-Form App I get the error message mentioned above...
I just inserted a button to go through the tutroial "Hello World" but could not compile it.....
I'm quite new to VS so if you need any further information please let me know (but also where to find it :-D)
Would be great to get some help!
Best regards
Joe

@anubi
Copy link

anubi commented Feb 22, 2021

I created a SignalR (but otherwise pretty much blank-slate) web app in VS 16.8.2 with linux-docker checked as an empty project option, build the nearly empty solution with no issues and attach a debugger on Startup.cs. I then decide to detach the debugger ("stop debugging") and rebuild. It gave me a permission denied error, so I went in and manually killed and removed the pertaining docker images. Rebuilding after doing that is creating the following stack trace

1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: The "CreateAppHost" task failed unexpectedly.
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: System.IO.IOException: Incorrect function.
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018:
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: at Microsoft.NET.HostModel.AppHost.BinaryUtils.CopyFile(String sourcePath, String destinationPath)
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,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\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute()
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(460,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

Restarting my computer seems to fix the issue. But that's hardly a good solution since I'm frequently debugging. Not sure what's going on with docker, but it seems to be the culprit in this scenario. I'm updating VS to see if this resolves it.

edit: Updated. Also made a new blank project w/o docker. Issue is now persisting even after a restart. Have no idea what's going on. It's very strange. I will try .netcore3.0 and see what's up.

edit edit: IT admin reached out. I was flagged for anti-virus on apphost.exe, that explains it. So it's the same issue. (webroot antivirus)

@rohanaceres
Copy link

What fixed for me was deleting all bin and out folder.

This was caused by using VSCode as admin. Apparently after I build solution with VSCode as admin, some gets messed up resulting with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests