Bug 23653 - [XA 4.18] "Access to the path ...obj\Debug\res\... is denied" when resource files are marked as read-only
Summary: [XA 4.18] "Access to the path ...obj\Debug\res\... is denied" when resource f...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.18.0
Hardware: PC All
: High major
Target Milestone: 4.18.1
Assignee: dean.ellis
URL:
: 23639 23753 ()
Depends on:
Blocks:
 
Reported: 2014-10-06 13:50 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2014-10-28 19:43 UTC (History)
13 users (show)

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


Attachments
Test case (16.68 KB, application/zip)
2014-10-06 13:50 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Diagnostic build output (128.85 KB, text/plain)
2014-10-06 13:50 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Test case 2 (14.08 KB, application/zip)
2014-10-16 18:39 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Diagnostic build output 2 (125.11 KB, text/plain)
2014-10-16 18:44 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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 or GitHub 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:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2014-10-06 13:50:12 UTC
Created attachment 8319 [details]
Test case

[XA 4.18] "Access to the path ...obj\Debug\res\... is denied" when resource files are marked as read-only

This problem is particularly noticeable when using TFS because TFS automatically marks all of the resources as read-only.


Regression status: REGRESSION

### Good
#### Windows
Xamarin   3.6.262.0 (21b7dba8736246dfd10e3f19a92ed68f1b30abfd)
Xamarin.Android   4.16.0.17 (2a7b68212b17c903160fbd8e0106babb299d1be3)
Xamarin.iOS   8.0.66.0 (3e201c8aa14879773f966f483329bcda49fd3a41)

#### Mac
Xamarin.Android 4.16.0.17 (2a7b68212b17c903160fbd8e0106babb299d1be3)

### Bad
#### Windows
Xamarin   3.7.201.0 (58a59ecb5fa40a0a2e97617c36c069074404c6ae)
Xamarin.Android   4.18.0.32 (04399d62cfc00624d575239d1762ea4fd6d012e2)
Xamarin.iOS   8.2.0.0 (ff9d4a06f588a29e1db224ecd4216f68a9106299)

#### Mac
Xamarin.Android 4.18.0.32 (04399d62cfc00624d575239d1762ea4fd6d012e2)
http://download.xamarin.com/MonoforAndroid/Mac/mono-android-4.18.0-32.pkg


## Steps to reproduce

Attempt to build the attached project on either OS X or Windows:

> msbuild /t:Build AndroidApp1\AndroidApp1.csproj

or

> xbuild /t:Build AndroidApp1/AndroidApp1.csproj


### Steps followed to create the test case

1. Create a Android App
2. Add an image into the `Resources\drawable` folder
3. In Windows Explorer, enable the "Read-only" attribute for the image file.
4. Add an ImageView to `Main.axml`, and set the `src` to the image resource from steps 2 and 3.


## Result

> Error	1	The "CopyAndConvertResources" task failed unexpectedly.
> System.UnauthorizedAccessException: Access to the path 'C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\obj\Debug\res\drawable\image1.png' is denied.
>    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 Xamarin.Android.Tasks.CopyAndConvertResources.Execute()
>    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
>    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()	AndroidApp1


## Workaround

After the first failed build attempt, build the project again. This time it will succeed.
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-06 13:50:48 UTC
Created attachment 8320 [details]
Diagnostic build output
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-06 13:55:34 UTC
*** Bug 23639 has been marked as a duplicate of this bug. ***
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-06 13:58:38 UTC
Many users have reported this problem on the forums:
http://forums.xamarin.com/discussion/25411/copyandconvertresources-task-failed-in-xamarin-3-7-201

We are also receiving many e-mail support cases about the issue.
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-06 14:24:29 UTC
I've posted a forum announcement about the issue with several possible workarounds:
http://forums.xamarin.com/discussion/25489/copyandconvertresources-task-failed-unexpectedly-read-only-resources
Comment 6 Jonathan Pryor 2014-10-13 11:19:42 UTC
Fixed in monodroid/41c7adf7 and monodroid-4.18-series/186c6bf7.
Comment 7 dean.ellis 2014-10-14 08:20:12 UTC
*** Bug 23753 has been marked as a duplicate of this bug. ***
Comment 8 Mohit Kheterpal 2014-10-14 12:11:49 UTC
I am able to reproduce this issue with failed builds mention in bug description.

I have checked this issue with XA 4.18.0-38 and XVS 3.7.219 and now this issue is working fine i.e. attached project build successfully in first attempt having .png file in read only mode.

Hence closing this issue.

Thanks
Comment 9 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-16 18:39:15 UTC
Created attachment 8438 [details]
Test case 2

Shoot. My fault. My test case was not sufficient. I should have marked the entire `Resources\` folder read-only recursively.

Here is a new test, better test case. It's simply the "Blank App (Android)" project with the entire `Resources\` directory marked read-only. Apparently the "special" `.tmp` files were not covered by the first fix.


## New result

> error MSB4018: The "CopyAndConvertResources" task failed unexpectedly. [C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\AndroidApp1.csproj]
> error MSB4018: System.UnauthorizedAccessException: Access to the path 'C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\obj\Debug\res\layout\main.xml.tmp' is denied. [C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\AndroidApp1.csproj]
> error MSB4018:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) [C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\AndroidApp1.csproj]
> error MSB4018:    at System.IO.File.InternalDelete(String path, Boolean checkHost) [C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\AndroidApp1.csproj]
> error MSB4018:    at System.IO.File.Delete(String path) [C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\AndroidApp1.csproj]
> error MSB4018:    at Xamarin.Android.Tasks.CopyAndConvertResources.Execute() [C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\AndroidApp1.csproj]
> error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\AndroidApp1.csproj]
> error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() [C:\Users\Windows User\Desktop\AndroidApp1\AndroidApp1\AndroidApp1.csproj]


## New version information

Xamarin   3.7.226.0 (bde1ced5c221b04ff6c6c147e50fd5ca0000cbd1)
Xamarin.Android   4.18.0.38 (c0168255507205e3f50aba560ccf971c41a682ff)
Xamarin.iOS   8.2.0.0 (06812e63c56a62c5ed6298167da3c71c6baf8852)
Comment 10 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-16 18:44:10 UTC
Created attachment 8439 [details]
Diagnostic build output 2
Comment 11 pragma.mobilexp 2014-10-17 02:13:19 UTC
Any idea on when this will be finally fixed.  The workarounds provide for an extremely frustrating workflow when using TFS as source control provider.
Comment 12 Ryan Hatfield 2014-10-17 11:46:22 UTC
Not sure if this is because of this, but after I updated to the 'fixed' version, now whenever I edit resources, visual studio locks up tight as a drum and i have to End Task. I don't have an effective way to reproduce this, but worth making a note.
Comment 13 Jonathan Pryor 2014-10-23 16:20:10 UTC
This should be fixed in monodroid-4.18-series/5e111970.
Comment 14 Mohit Kheterpal 2014-10-27 14:28:03 UTC
I have checked this issue with XA 4.18.1-1 and followed following steps :

Download attached project in comment 9 and Manually change its resource folder and its file as Read-only and then build it. Then it gives same error.

Getting same behaviour with windows using  following environment :

Xamarin   3.7.246.0 (ee1ad29770815d82d8be308c7406ac29b3c789d2)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.18.1.1 (ef5be128e3e779cb7284bd3b288159c885d83b52)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.4.0.0 (209abebbd8f1a292d042420edb45fa5fbd3f017b)

Mac info : 
=== Xamarin Studio ===

Version 5.5.3 (build 6)
Installation UUID: 45555ffd-f3f0-4f29-9543-e369d711ab7d
Runtime:
	Mono 3.10.0 ((detached/e204655)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000023

=== Xamarin.Android ===

Version: 4.18.1 (Enterprise Edition)
Android SDK: /Users/xamarin77/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1 (6602)
Build 6A1052c

=== Xamarin.iOS ===

Version: 8.4.0.15 (Enterprise Edition)
Hash: 08968c4
Branch: 
Build date: 2014-10-20 21:48:06-0400

=== Xamarin.Mac ===

Version: 1.11.1.3 (Enterprise Edition)

=== Build Information ===

Release ID: 505030006
Git revision: fbe3e9453daf6a3bb9a9709ed22bec35f7c9056b
Build date: 2014-10-23 13:08:38-04
Xamarin addins: e44add2b39de4dd57c0742bb2e620dfad84c64c6

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin77s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 15 dean.ellis 2014-10-27 14:35:34 UTC
Mohit can you attach the diagnostic build output please.
Comment 16 Mohit Kheterpal 2014-10-27 14:39:28 UTC
Build output from terminal : https://gist.github.com/Mohit-Kheterpal/6f639c928f48b4845cbd
Diagnostic build output from XS : https://gist.github.com/Mohit-Kheterpal/7dda1712552fd474ce28
Comment 17 dean.ellis 2014-10-27 15:03:52 UTC
Fixed the Resource.desginer.cs issue in monodroid-4.18-series/eaf28a2