Bug 24206 - [XA 4.18] "Access to the path ...\obj\Debug\__library_projects__\...\library_project_imports\assets\... is denied" when asset files in class library are marked as read-only
Summary: [XA 4.18] "Access to the path ...\obj\Debug\__library_projects__\...\library_...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.18.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: 4.18.1
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2014-10-31 19:49 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-04-02 10:09 UTC (History)
6 users (show)

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


Attachments
Test case (20.10 KB, application/zip)
2014-10-31 19:49 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Diagnostic build output (34.96 KB, application/x-gzip)
2014-10-31 19:51 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-31 19:49:50 UTC
Created attachment 8585 [details]
Test case

"Access to the path ...\obj\Debug\__library_projects__\...\library_project_imports\assets\... is denied" during rebuild when asset files in class library are marked as read-only

This is a follow-up to bug 23653.


Regression status: regression between Xamarin 3.6.262 and 3.7.248

This bug is already fixed in monodroid-4.18/fb680aed (and also in the corresponding commits for 4.20 and master).


## Steps to reproduce without TFS on Windows

1. Set the `ClassLibrary1\Assets\Square.png` in the attached test case to read-only. 

2. Build the project:
> msbuild /t:Build AndroidApp1\AndroidApp1.csproj

3. Rebuild the project:
> msbuild /t:Rebuild AndroidApp1\AndroidApp1.csproj


## Steps to reproduce with TFS

1. Setup TFS (tested with TFS Express 2013) following the Xamarin guides [1, 2].
> [1] http://developer.xamarin.com/guides/cross-platform/ci/configuring_tfs/ 
> [2] http://developer.xamarin.com/guides/cross-platform/ci/tfs_walkthrough/

2. Add the attached test project under source control and check it in, but exclude `Resource.Designer.cs` from the check-in. This will allow the project to build successfully on XVS 3.6.262 (XA 4.16).

3. Set "Process -> TF Version Control -> Clean Workspace" to "False" in the build definition.

4. Queue the build definition on the build TFS build controller. 

5. After the build completes, queue the build again.


## Result

The second build fails with the following error:

> Target "_ExtractLibraryProjectImports: (TargetId:27)" in file "C:\Program
> Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets" from
> project "C:\Builds\1\TeamProject1\AndroidApp1-Resources\src\AndroidApp1\
> AndroidApp1\AndroidApp1.csproj" (target "_GetLibraryImports" depends on it):
> Using "ResolveLibraryProjectImports" task from assembly "C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll".
> Task "ResolveLibraryProjectImports" (TaskId:62)
>   ResolveLibraryProjectImports Task (TaskId:62)
>     ImportsDirectory: library_project_imports (TaskId:62)
>     OutputDirectory: obj\Debug\ (TaskId:62)
>     OutputImportDirectory: obj\Debug\__library_projects__\ (TaskId:62)
>     UseShortFileNames: False (TaskId:62)
>     Assemblies:  (TaskId:62)
>       C:\Builds\1\TeamProject1\AndroidApp1-Resources\bin\ClassLibrary1.dll (TaskId:62)
>       C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v4.4\Mono.Android.dll (TaskId:62)
>       C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll (TaskId:62)
>       C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Core.dll (TaskId:62)
>       C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.dll (TaskId:62)
>       C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Xml.dll (TaskId:62)
>       C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Xml.Linq.dll (TaskId:62)
> C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(665,2):
> monodroid error XA0000: Unexpected error - Please file a bug report at
> http://bugzilla.xamarin.com. Reason: System.UnauthorizedAccessException:
> Access to the path "C:\Builds\1\TeamProject1\AndroidApp1-Resources\src\
> AndroidApp1\AndroidApp1\obj\Debug\__library_projects__\ClassLibrary1\
> library_project_imports\assets\Square.png" is denied.
>     Jars:  (TaskId:62)
>     ResolvedResourceDirectories:  (TaskId:62)
>     ResolvedAssetDirectories:  (TaskId:62)
>     ResolvedEnvironmentFiles:  (TaskId:62)
> Done executing task "ResolveLibraryProjectImports" -- FAILED. (TaskId:62)


## Additional information

I can verify that this is fixed in the development branch:
monodroid-4.18/fb680aed

Replacing the files in `C:\Program Files (x86)\MSBuild\Xamarin\Android` with the versions from the Mac installer [1] fixes the problem for both sets of steps to reproduce.

> [1] /Library/Frameworks/Xamarin.Android.framework/Versions/4.18.1-6/lib/xbuild/Xamarin/Android/*


## Version information

Xamarin   3.7.248.0 (8ca7d11db8a6f874c6cd2de6d9ca0f511867ce91)
Xamarin.Android   4.18.1.3 (5474129af31e9d3a86cb7482c7c5c7a30ad315f1)
Xamarin.iOS   8.4.0.0 (209abebbd8f1a292d042420edb45fa5fbd3f017b)
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-31 19:51:37 UTC
Created attachment 8586 [details]
Diagnostic build output
Comment 2 Akhilesh kumar 2014-11-03 05:28:11 UTC
I also able to reproduce this issue with following steps:

1. Downloaded attached sample
2. Set the `ClassLibrary1\Assets\Square.png` to read-only
3. Build the project:
> msbuild /t:Build AndroidApp1\AndroidApp1.csproj

4. Rebuild the project:
> msbuild /t:Rebuild AndroidApp1\AndroidApp1.csproj

Actual result: 
Project is build successfully at first time but when we rerun the project then project gives build error.

 monodroid error XA0000: Unexpected error - Please file a bug report at http:
//bugzilla.xamarin.com. Reason: System.UnauthorizedAccessException: Access to t
he path "C:\Users\Akhilesh\Downloads\ClassLibraryAssets\AndroidApp1\obj\Debug\_
_library_projects__\ClassLibrary1\library_project_imports\assets\Square.png" is
 denied. [C:\Users\Akhilesh\Downloads\ClassLibraryAssets\AndroidApp1\AndroidApp
1.csproj] 

Screencast: http://screencast.com/t/w7Vbty7Z7s 
Build output: https://gist.github.com/AkhileshKumar01/763a88aeea76453cb140

Build info: 
Xamarin   3.7.248.0 (8ca7d11db8a6f874c6cd2de6d9ca0f511867ce91)
Xamarin.Android   4.18.1.3 (5474129af31e9d3a86cb7482c7c5c7a30ad315f1)
Xamarin.iOS   8.4.0.0 (209abebbd8f1a292d042420edb45fa5fbd3f017b)
Comment 3 Peter Collins 2014-11-03 17:01:15 UTC
The specific repro steps still fail for me with the latest fix, however this failure appears not to be a regression.

It looks like we're still hitting this readonly error when executing the clean target, which is ran as part of /t:Rebuild.

Diagnostic rebuild output:
https://gist.github.com/pjcollins/895e35f970db6444cc58
Comment 4 dean.ellis 2014-11-04 11:18:54 UTC
Fixed in monodroid/master/00fb40b4
Comment 5 Ram Chandra 2015-02-10 07:40:28 UTC
To verify this issue, I have checked this issue with following build 

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.51641
Installed Version: Professional
Xamarin   3.9.293.0 (080a254)
Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Xamarin.iOS   8.6.1.0 (3b3ef438017c7ecf486defa9e01567a5f2b3cb2a)
Xamarin.iOS Unified Migration   1.0

Steps I followed:

1. Downloaded attached sample
2. Set the `ClassLibrary1\Assets\Square.png` to read-only
3. Open Visual Studio Developer Command prompt ("Run as administrator)
4. Build project using following command on command prompt

> msbuild /t:Build AndroidApp1\AndroidApp1.csproj

4. Rebuild the project:
> msbuild /t:Rebuild AndroidApp1\AndroidApp1.csproj

When I build and rebuild the application I am not getting any error/exception. Application builds and rebuilds successfully using msbuild command.

Build output: https://bugzilla.xamarin.com/show_bug.cgi?id=24206

This issue has been fixed. Hence I am closing this issue.