Bug 56587 - Companion to Bug 56275 for example scenario that hits "Could not copy "obj\Debug\..." to "bin\Debug\...". Exceeded retry count of 10."
Summary: Companion to Bug 56275 for example scenario that hits "Could not copy "obj\De...
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: General (show other bugs)
Version: 4.5.0 (15.2)
Hardware: PC Windows
: Highest critical
Target Milestone: 15.2.2
Assignee: Bugzilla
URL:
Depends on:
Blocks: 56275
  Show dependency tree
 
Reported: 2017-05-18 03:03 UTC by Brendan Zagaeski (Xamarin Support)
Modified: 2017-05-26 03:11 UTC (History)
7 users (show)

See Also:
Tags:
Is this bug a regression?: Yes
Last known good build: Xamarin.VisualStudio 4.4.0.34 (3f99c5a)


Attachments
Test case (168.99 KB, application/zip)
2017-05-18 03:03 UTC, Brendan Zagaeski (Xamarin Support)
Details

Description Brendan Zagaeski (Xamarin Support) 2017-05-18 03:03:58 UTC
Created attachment 22249 [details]
Test case

Companion to Bug 56275 for example scenario that hits "Could not copy "obj\Debug\..." to "bin\Debug\...". Exceeded retry count of 10."




## Steps followed to test

1. Open the attached test case in Visual Studio.

2. Restore the NuGet packages for the solution by right-clicking the solution node in the Solution Explorer and selecting "Restore NuGet Packages".

3. Quit Visual Studio, and then reopen the solution once more.  (Testing note: The idea behind this is just to get the NuGet packages set up as they would be for the typical usage scenario case.)

4. Wait for the Xamarin remote Mac connection to connect completely.

5. Add a typo in FormsClassLibrary1.cs.  For my tests I changed "CenterAndExpand" to "CenterAndExpan".

6. Set the iOS app project as the startup project.

7. Attempt to build the iOS app project in the "Debug|iPhoneSimulator" configuration via "Build > Build FormsPortable1.iOS".

8. The build fails as expected at this step due to the intentional typo introduced at step 3.  Proceed to the next step.

9. Correct the typo in FormsClassLibrary1.cs.

10. Again build the iOS project.

11. If the built completes successfully, repeat steps 5-10.




## BAD Results

The build eventually fails on one of the repetitions of steps 5-10 because "FormsPortable1.dll" is "in use by another process":

> Microsoft.Common.CurrentVersion.targets(3989,5): warning MSB3026:
> Could not copy "obj\Debug\FormsPortable1.dll" to
> "bin\Debug\FormsPortable1.dll". Beginning retry 10 in 1000ms. The
> process cannot access the file 'bin\Debug\FormsPortable1.dll' because
> it is being used by another process.

> Microsoft.Common.CurrentVersion.targets(3989,5): error MSB3027: Could
> not copy "obj\Debug\FormsPortable1.dll" to
> "bin\Debug\FormsPortable1.dll". Exceeded retry count of 10. Failed.



## Detailed results: number of repetitions of steps 5-10 until failure, 6 trials per environment



### Visual Studio 2017 version 15.2

2 4 2 2 2 2



### Visual Studio 2015 Update 3 

2 2 3 2 2 3



### Notes

In the trials where more than 2 repetitions of steps 5-10 were required, the warning did sometimes appear in an earlier repetition, but apparently the handle on the file was released soon enough for the build process to complete successfully in those repetitions.




## Testing environment info



### "Tool > Options > Build and Run" settings for all trials

> maximum number of parallel project builds:            4
> Only build startup projects and dependencies on Run:  ON
> On Run, when build or deployment errors occur:        Prompt to launch
> MSBuild project build output verbosity:               Diagnostic
> MSBuild project build log file verbosity:             Minimal


### Windows

Microsoft Visual Studio Enterprise 2017 
Version 15.2 (26430.6) Release

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3

Microsoft .NET Framework
Version 4.6.01586

Windows 10 (64-bit) version 1607 (OS Build 14393.1198)
US English locale, US Eastern time zone



### Mac

Xamarin.iOS 10.10.0.33 (d15-2: 3e5ac5ff)
Mono 5.0.0.100 (2017-02/9667aa6)

Xcode 8.3, Build version 8E162

macOS 10.12.4
Comment 3 Brendan Zagaeski (Xamarin Support) 2017-05-18 04:51:10 UTC
## Experiment 1: Remove the Android project from the solution before step 3

Number of repetitions of steps 5-10 until failure, Visual Studio 2017 version 15.2, 3 trials

- NO failures after 12 repetitions
- NO failures after 12 repetitions
- NO failures after 12 repetitions




## Experiment 2: Remove the iOS project, and build the Android project instead

Number of repetitions of steps 5-10 until failure, Visual Studio 2017 version 15.2, 6 trials

4 2 2 2 3 5




## Experiment 3: Regression status for Android project behavior from Experiment 2: regression between Xamarin 15.1 and 15.2 releases

This test scenario matches the original user reports on Bug 56275 for regression status, suggesting that resolving this test particular scenario might be sufficient to resolve all of the user reports.



Number of repetitions of steps 5-10 until failure, Visual Studio 2015 Update 3 + Xamarin.VisualStudio 4.4.0.34 (3f99c5a) "Xamarin 15.1 release", 2 trials

- NO failures after 12 repetitions
- NO failures after 12 repetitions



Number of repetitions of steps 5-10 until failure, Visual Studio 2015 Update 3 + Xamarin.VisualStudio 4.5.0.443 (c871575) "Xamarin 15.2 release", 3 trials

3 4 3




## Notes

A spot check of the handles using [1] for the original test scenario from Comment 0 as well as the scenario from Experiment 2 and 3 showed `devenv.exe` to be the process with an open handle to the "bin\Debug\FormsPortable1.dll" file.

[1] https://technet.microsoft.com/sysinternals/handle.aspx
Comment 4 Brendan Zagaeski (Xamarin Support) 2017-05-19 16:20:14 UTC
## Updating resolution status from Bug 56275, Comment 125

Fixed in version 4.5.0.473 (d15-2)

Author: joj
Commit: 030924d98ba23d814e0183b85f297c568b4743ed (xamarin/XamarinVS)
Comment 5 Brendan Zagaeski (Xamarin Support) 2017-05-19 16:20:46 UTC
## Preliminary verification status of the candidate change from commit 030924d (from Bug 56275, Comment 125)

GOOD.

Number of repetitions of steps 5-10 until failure, in Visual Studio 2017 version 15.2 + the experimental change, 3 trials

- NO failures after 12 repetitions
- NO failures after 12 repetitions
- NO failures after 12 repetitions




## Testing notes

For this preliminary local verification, I used an unsigned local build, and I used the scenario from "Experiment 2": I removed the iOS project from the solution, and built the Xamarin.Android project.  I will reverify the original scenario from Comment 0 as well as the scenario from "Experiment 2" once a full CI build is available.
Comment 6 Brendan Zagaeski (Xamarin Support) 2017-05-23 00:38:58 UTC
## Supplemental background information: excerpt of the call stack holding the file handle in this particular scenario

> Mono.Cecil.dll!Mono.Cecil.ModuleDefinition::ReadModule
> Xamarin.VisualStudio.Android.dll!Java.Interop.Tools.Cecil.DirectoryAssemblyResolver::ReadAssembly
> Xamarin.VisualStudio.Android.dll!Java.Interop.Tools.Cecil.DirectoryAssemblyResolver::Load
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.Setup.AdditionalResourcesInstaller::GetAssemblyInfo
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.Setup.AdditionalResourcesInstaller::GetAssembliesInfo
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.Setup.AdditionalResourcesProjectSetup::RefreshStatus
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.Setup.AdditionalResourcesProjectSetup::RefreshStatus
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.Setup.AdditionalResourcesProjectSetup::VerifyReferences
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.Setup.AdditionalResourcesProjectSetup::Verify
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.Setup.AndroidSetup::VerifyBuild
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.Setup.AndroidSetup::OnBuildBegin
> EnvDTE.dll!EnvDTE._dispBuildEvents_SinkHelper::OnBuildBegin



## Steps followed to collect the call stack

1. Complete steps 1-9 from Comment 0 to prepare to replicate.

2. Open the "Collect > Collect" window in PerfView [1, 2].

3. Under "Advanced Options" enable the "File I/O" setting, and then start the data collection.

4. Switch back to Visual Studio and replicate the error.

5. Stop data collection in PerfView.

6. Open the "Events" item from the trace in PerfView, and navigate to "Windows Kernel/FileIO/Read".

7. Filter the events to ones where the FileName includes the problematic file "bin\Debug\FormsPortable1.dll".

8. Click on the Time value for one of the events and type Alt-S to open the corresponding stack.

[1] http://www.microsoft.com/download/details.aspx?id=28567
[2] https://github.com/Microsoft/perfview
Comment 9 Brendan Zagaeski (Xamarin Support) 2017-05-23 17:26:44 UTC
## Verification status part 1: Verified fixed in Xamarin.VisualStudio 4.5.0.475 (70f1268), using the test scenario from Comment 0

(Note that as of the time of this comment, these builds are not yet published publicly, but they are the candidate versions targeted for release today.)



### Visual Studio 2017 version 15.2 (26430.9), with the original test scenario from Comment 0

Number of repetitions of steps 5-10 until failure, Xamarin.VisualStudio 4.5.0.475 (70f1268) "Xamarin 15.2.2 release", 3 trials

- NO failures after 12 repetitions
- NO failures after 12 repetitions
- NO failures after 12 repetitions



### Visual Studio 2015 Update 3, with the original test scenario from Comment 0

Number of repetitions of steps 5-10 until failure, Xamarin.VisualStudio 4.5.0.475 (70f1268) "Xamarin 15.2.2 release", 2 trials

- NO failures after 12 repetitions
- NO failures after 12 repetitions




## Additional testing environment info updates compared to Comment 0

### Mac

Xamarin.iOS 10.10.0.36 (d15-2: d2270eec)
Mono 5.0.1.1 (2017-02/5077205)
Comment 10 Brendan Zagaeski (Xamarin Support) 2017-05-24 04:55:51 UTC
## Brief experiment to test a non-standard installation strategy for Visual Studio 2017 Preview

See [1] for the details about how to try this approach with the currently available Xamarin for Visual Studio 2015 download [2] and Visual Studio 2017 Preview.  It was effective in my brief local tests, and users are welcome to try this strategy too if they like, but please note that because it is non-standard, it is not a supported scenario for any secondary issues that might arise.

(I experimented with this approach using Visual Studio 2017 Preview version 15.3 (26510.0-Preview) plus the latest Visual Studio 2015 installer [2].)



Number of repetitions of steps 5-10 until failure, 1 trial, building the iOS project as in Comment 0

- NO failures after 12 repetitions



Number of repetitions of steps 5-10 until failure, 1 trial, building the Android project

- NO failures after 12 repetitions




## Links

[1] https://gist.github.com/brendanzagaeski/5cebb11c433f3715da520b6ee1fea9ed
[2] https://dl.xamarin.com/XamarinforVisualStudio/Windows/Xamarin.VisualStudio_4.5.0.475.msi
Comment 11 Brendan Zagaeski (Xamarin Support) 2017-05-26 03:11:47 UTC
## Verification of temporary workaround for VS 2017 (or any version of VS) from Bug 56275, Comment 179



Number of repetitions of steps 5-10 until failure, 2 trials, building the iOS project as in Comment 0

- NO failures after 12 repetitions
- NO failures after 12 repetitions



Number of repetitions of steps 5-10 until failure, 2 trials, building the Android project

- NO failures after 12 repetitions
- NO failures after 12 repetitions




## Visual Studio version info for these tests

Microsoft Visual Studio Enterprise 2017
Version 15.2 (26430.6) Release

Note You need to log in before you can comment on or make changes to this bug.