Bug 31423 - [XVS] Locked .dll files: Could not copy "... PortableClassLibrary1.dll" to "bin\Debug\PortableClassLibrary1.dll". Exceeded retry count of 10. Failed.
Summary: [XVS] Locked .dll files: Could not copy "... PortableClassLibrary1.dll" to "b...
Status: RESOLVED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: General ()
Version: 3.11 (C5)
Hardware: PC Windows
: Normal normal
Target Milestone: 4.0.0 (C6)
Assignee: vsx
URL:
Depends on:
Blocks:
 
Reported: 2015-06-26 16:47 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2017-05-31 13:35 UTC (History)
16 users (show)

Tags: BZSRC5SR2S1
Is this bug a regression?: ---
Last known good build:


Attachments
Verbose build log (544.76 KB, text/plain)
2015-07-07 20:04 UTC, Ray Perkins
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2015-06-26 16:47:30 UTC
[XVS C5SR2] Locked .dll files: Could not copy "... PortableClassLibrary1.dll" to "bin\Debug\PortableClassLibrary1.dll". Exceeded retry count of 10. Failed.


This is a preliminary bug report to start tracking a new problem that has similar symptoms to Bug 26841.


I do not yet have a set of steps to reproduce the problem, nor do I have log files, but it "feels" like this problem could have been directly caused by the fix for Bug 26841 or one of the project-cleaning fixes related to debugging. Those changes have only been present in the most recent XamarinVS releases.

I will expand on this bug report if I am able to reproduce the problem again.




## Regression status: suspected regression between Cycle 5 Service Release 1 and Cycle 5 Service Release 2.




## Symptoms

The symptoms closely resemble Bug 26841, but importantly the files that are locked in this case are `.dll` files _not_ `.dll.mdb` files. The evidence available so far suggests that the problem is specific to Portable Class Libraries.


### Error messages from the Error List

> Could not copy "C:\source\UnifiedSingleViewIphone1\PortableClassLibrary1\bin\Debug\PortableClassLibrary1.dll" to "bin\Debug\PortableClassLibrary1.dll". Exceeded retry count of 10. Failed.

> Unable not copy "C:\source\UnifiedSingleViewIphone1\PortableClassLibrary1\bin\Debug\PortableClassLibrary1.dll" to "bin\Debug\PortableClassLibrary1.dll". The process cannot access the file 'bin\Debug\PortableClassLibrary1.dll' because it is being used by another process.




## Reports to date

- I encountered the problem once myself while troubleshooting an unrelated issue.

- A customer has also reported the issue once here: https://kb.xamarin.com/agent/case/177604.
Comment 1 mitchell balsam 2015-06-26 19:42:29 UTC
Im having the same problem, and were NOT using a PCL.

I have two dll's in Class library that exhibit the problem.  What i have to do is to exit VS. Kill all MSBuild processes, delete the dll's and then restart VS.

I can run the SysInternals program Handle.exe and it says that devenv owns the handle to the file.
Comment 3 Ray Perkins 2015-07-07 20:03:08 UTC
I have the issue on occasion as well. The "The process cannot access the file" issue only seems to affect references to portable library projects. The error is only appears when build/rebuilding the application project.

A clean removes all file except the .dll file that causes the problem.

The work around I use to close Visual Studio 2013, delete the build folder for the application project and reopen VS were the application can be build once before needing to perform the work around again.
Comment 4 Ray Perkins 2015-07-07 20:04:25 UTC
Created attachment 11921 [details]
Verbose build log

The 'Exceeded retry count of 10' error message is on line 4077.
Comment 5 Ian Ceicys 2015-07-13 12:56:03 UTC
I worked with another customer and we were able to resolve the issue the customer was facing with this post by using the pre-build event in the VS project properties Build Events configuration section:

http://stackoverflow.com/questions/15689353/visual-studio-2012-warning-msb3026-could-not-copy-dlls

We added the following to the VS project properties Build Events configuration section:

if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

If other customers are experiencing this issue please try the above and if you have a case that is easy to reproduce please attach it here so we can investigate it further.
Comment 6 Richard Massé 2015-07-13 13:07:51 UTC
I updated to Xamarin Forms 1.4.3.6376 in the morning today and i have not
received this error since this time. I keeping my fingers crossed and hope to
never saw it agai
Comment 7 Richard Massé 2015-07-15 15:19:53 UTC
Error came back today. So i got a break of 2 days.
Comment 8 mitchell balsam 2015-07-21 18:07:23 UTC
I included the Build Events logic and it did not help.

We do not have a case that is easy to reproduce sorry.

Productivity is grinding to a halt.
Comment 9 Ian Ceicys 2015-07-22 10:13:19 UTC
Hi mitchell. I've followed up on email and I'm hoping we can have a GoToMeeting screen sharing session today in order to figure out what is happening with your specific configuration and how we can resolve the issue.

Please let me know the version information (visual studio version\Xamarin) you are running so I can setup an environment to more easily reproduce the issue.
Comment 10 Ray Perkins 2015-07-29 18:40:58 UTC
Hi Ian and Mitchell

Did you manage to setup a screen sharing session and if so did it have a positive result?

Today I updated some nuget packages and did a clean then rebuild. The rebuild failed because some files failed to be copied from the new nuget version. And the copy failed because some files with the same name but an older version were not be cleaned from the build folder.
So I removed the files and kept a copy of them. Then the rebuild would work as well as subsequent cleans. I then copied the previous files that failed to be cleaned back into the build folder and the rebuild/clean would fail again. I did this several times to confirm the error was repeatable.

I concluded that VS would not remove the files unless the file name and the file version matched. 
I now felt pretty clever as I seemed to have found a repeatable mechanism for the error and so I made projects to simulate the problem. But, I can not reproduce the issue in the new projects... darn. Furthermore, after closing and reopening VS I can no longer reproduce it in the original project.

The bright side to all this is that my original project is building and cleaning ok now. Or, for now, I should say.
Comment 11 Nathan B. Evans 2015-08-11 07:52:05 UTC
This is happening to me since updating my Xamarin.Android and other things.

handle.exe from sysinternals confirms devenv.exe is holding the file lock on around 5 of my product's DLLs. Including FSharp.Core.dll for some reason, as well.

Handle v3.51
Copyright (C) 1997-2013 Mark Russinovich
Sysinternals - www.sysinternals.com

cmd.exe            pid: 3280   type: File           1BC: C:\Sandbox\Singapore\Singapore.Mobile.Android
devenv.exe         pid: 4908   type: File          1054: C:\Users\nbevans\AppData\Local\Microsoft\VisualStudio\12.0\ProjectAssemblies\fddedgxh01\Singapore.Mobile.Android.dll
devenv.exe         pid: 4908   type: File          19AC: C:\Sandbox\Singapore\Singapore.Mobile.Android\bin\Debug\Singapore.Core.Configuration.dll
devenv.exe         pid: 4908   type: File          1BC0: C:\Sandbox\Singapore\Singapore.Mobile.Android\bin\Debug\FSharp.Core.dll
devenv.exe         pid: 4908   type: File          1F14: C:\Sandbox\Singapore\Singapore.Mobile.Android\bin\Debug\Singapore.Core.Metaforms.dll
devenv.exe         pid: 4908   type: File          262C: C:\Sandbox\Singapore\Singapore.Mobile.Android\bin\Debug\Singapore.Mobile.Storage.dll
devenv.exe         pid: 4908   type: File          29AC: C:\Sandbox\Singapore\Singapore.Mobile.Android\bin\Debug\Singapore.Core.Metaforms.Engine.dll
Comment 12 Nathan B. Evans 2015-08-11 08:33:34 UTC
https://gist.github.com/nbevans/45dd66f147277a2ea3dd

Here is a workaround I just came up with using SysInternals' handle.exe tool. My F# script will enumerate the relevant locked files and then forcefully kill those open file handles. I've inserted this script into my pre-build event on the project and my productivity has now been restored.
Comment 17 Akhilesh kumar 2015-10-01 15:49:02 UTC
I have tried to reproduce this issue at my end with XVS 3.11 builds, but I am unable to reproduce the reported behavior

I have used following steps:
1. Created Android/XamarinPortable Forms application in XS- Windows
2. I am able to run android application successfully 
3. Now I have open same in VS Windows
4. Run same android/XamarinPortable sample in VS with XVS 3.11.1433
5. I have run application multiple times

Result: I am successfully able to deploy android application on device every time through VS.

Build used: 
Windows: XVS 3.11.1433 and XS 5.11 (build 29)

I am not sure about its correct steps to reproduce/verify this issue.

Could you please provide a testcase? So that I can verify this issue efficiently.
Comment 19 Reader Man 2017-05-31 05:34:59 UTC
I began having this issue suddenly in VS 2017 u2, then switched to VS 2017 u3 preview, and the error did not happen but after several days, it began coming, and restarting VS 2017 u3 preview, will stop it from appearing, but after several builds, it returns, and again i need to restart it, but when i installed the .vsix thanks to @RSUK, it stopped at both VS 2017 u2 & u3.

Shortly i finished my project, so i don't know if i continued for long time it will return or not, but i am afraid that even when VS 2017 u3, comes to release, this error will return, so please, this a show stopper.

this is the build output from VS 2017 u3 preview:
https://goo.gl/sgGKF8

this is restated in here:
https://bugzilla.xamarin.com/show_bug.cgi?id=56275#c204

VS 2017 15.3 (26510.0-Preview)
Xamarin 4.6.0.560: installed throug the extensions and updates.
Solution: Xamarin.Forms
Startup project: the android project.

Regards.
Comment 20 Jose Gallardo 2017-05-31 13:35:08 UTC
You're right, the issue reported on Comment 19 was Bug 56275.
The root cause was identified, we found out it's totally unrelated to this bug 31423, although the symptom is the same, and it was already fixed (but not published yet for VS2017).

Thanks for reporting.