1

I've upgraded my Windows to 10.0.16299 (latest) and my Visual Studio to 15.5.1 (latest). Since then, I am seeing this error message when I clean or build my Xamarin solution containing an Android project:

obj\Debug\android\src\android\support\customtabs\CustomTabsClient_CustomTabsCallbackImpl.java:4: error: error while writing CustomTabsClient_CustomTabsCallbackImpl: obj\Debug\android\bin\classes\android\support\customtabs\CustomTabsClient_CustomTabsCallbackImpl.class (The process cannot access the file because it is being used by another process)

I figured that the locking process is Visual Studio itself after I tried to run and debug the app.

The issue appears no matter whether I want to run the app on an emulator or a connected real device.

There's lots of advice what to do when a process locks a file including SO such as the famous the process cannot access the file because it is being used by another process. However, all provided answers don't help as Visual Studio itself locks the file and the only workable workaround is to restart Visual Studio - that's not a solution.

What is causing this file to be locked? Any idea? Any advice?

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
  • Sounds like the process being debugged, or the emulator hosting the debugged process, itself, has not fully closed down, and is in a hung or semi-hung state. Have you checked the process manager to see if this is the case? You may want to to try adding `Environment.Exit()` to see if this helps come back to a good state. Another thing to check is, whether your access levels are the same between the two machines. Check not only the PC, but also at the emulator as well. Check everything, and ensure the access levels/modes are identical. – code4life Dec 12 '17 at 18:05
  • The emulator isn't the issue. I can close the emulator or I can even work on a real device instead and the same problem appears. The issue appeared straight after a the system upgrade without any code changes. As a subsequent issue, the app cannot be started anymore anyway (https://stackoverflow.com/questions/47732293/android-app-crashes-instantly-with-didnt-find-class-hash-mainapplication) which may or may not be related to that problem. Hence I cannot even run a single code line, the app crashes because whatever package VS generates: it's faulty. – Quality Catalyst Dec 12 '17 at 18:09

2 Answers2

2

Sometimes it helps to kill the MsBuild.exe. Also, you could find other solutions such as described here: Xamarin Android project cannot build....

Basically, it seems to be a problem with Studio 2017 Version 15.5. It will be fixed with the next versions probably.

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
valentasm
  • 2,137
  • 23
  • 24
  • Thank you! Killing the `msbuild` or any other process is, similar to what I mentioned in the question, rather a workaround, not a solution. I don't want to kill processes because they lock access to a file. Locking simply shouldn't happen. I haven't had an issue before 15.5.1, even 15.5 worked perfectly fine. However, yes, you might be right this is a 15.5.1 issue and might be fixed. If so, I wonder why no one else is reporting this problem :( – Quality Catalyst Dec 15 '17 at 03:09
  • What a tragedy. It was indeed an issue with VS 15.5.1. Microsoft's release notes for 15.5.2 mention this issue as number one in their bug fix list; see https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#15.5.2 – Quality Catalyst Dec 15 '17 at 18:45
  • Same issue with here. I'm running VS 2017, when running in debugging mode I get the exception but when I run without debugging no exception is thrown. – Carlo Luther Feb 12 '18 at 15:08
1

Darn it, my suggestions won't fit in the context of a comment, so here goes:

Sounds like the process being debugged, or the emulator hosting the debugged process, itself, has not fully closed down, and is in a hung or semi-hung state. Have you checked the process manager to see if this is the case? You may want to to try adding Environment.Exit() to see if this helps come back to a good state.

Another thing to check is, whether your access levels are the same between the two machines. Check not only the PC, but also at the emulator as well. Check everything, and ensure the access levels/modes are identical.

Finally, try running VS 2017 in administrator mode, and see if the problem persists. It's entirely possible that the level of access that you used to run pre-Windows 10 is different in the Win10 world that you live in, now.

code4life
  • 15,655
  • 7
  • 50
  • 82
  • Great suggestions. VS is running in Admin Mode: no difference. Emulator isn't the issue: same problem on connected real device. Access levels: I'll be comparing the two developer machines; thank you! Re close-down app process: it kills itself when starting it; see https://stackoverflow.com/questions/47732293/android-app-crashes-instantly-with-didnt-find-class-hash-mainapplication. Maybe you're pointing to the right problem. Will be checking this. – Quality Catalyst Dec 12 '17 at 18:18