Fixed: "CopyAndConvertResources" task failed unexpectedly (Read-only resources)

BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai
edited October 2014 in Xamarin.Android

Update October 30, 2014

The new complete fix has now been released to the stable channel:

  • Xamarin 3.7.248 for Windows
  • Xamarin.Android 4.18.1 for Mac

QA has now also added tests for building with TFS to the stable release process to guard against this kind of issue reappearing in the future.

Update October 16, 2014

The Xamarin 3.7.226 hotfix release that was just published to the stable channel includes a patch that explicitly removes all of the read-only flags from resources as they are copied into the obj\ folder.

Follow-up update: not yet fixed

Unfortunately the first test case I created for the bug report was foolishly not aggressive enough. I was basing the test case off the steps in another bug report, so it didn't cross my mind that there would be an important distinction between marking the whole Resources\ folder read-only compared to just a few specific resources.

I've re-opened the bug report with a better test case and directly notified the developers about the remaining problem with the *.xml.tmp files. Hopefully we can get a follow-up fix for this issue released very soon.


October 6, 2014

Xamarin 3.7.201 and Xamarin.Android 4.18 introduced a regression for resource files that are marked read-only on the file system. I've filed a high priority bug for the issue. Because many of the Xamarin developers are busy at Evolve this week, a hotfix for this issue might not make it out until next week.

This problem is particularly noticeable when using TFS because TFS automatically marks all of the resource files as read-only when it pulls them down from the source control server.

Workaround possibility 1: check out the Resources folder (recursively) from TFS

If you are performing a direct local build in Visual Studio for a solution that is under TFS source control, the following steps might be sufficient as a temporary workaround:

  1. Delete the bin\ and obj\ folders.
  2. Check out the Resources\ folder from TFS (recursively).

Workaround possibility 2: recursively remove the read-only flag from the Resources folder (using a "Pre-build event")

You can try removing the read-only flag from the Resources\ folder and all of its contents by hand. You could for example create a copy of the solution entirely outside of TFS or SourceGear Vault, or remove just the Resources\ folder from source control, and then use this technique.

If needed, you can use a "Pre-build event" to remove the read-only attributes at the start of each build, and then use a "Post-build event" command to put them back (under "Project Properties -> Build Events").

If you are using a TFS build agent, you will need to use some technique to remove the read-only attributes on the files after they have been copied to the build agent working directory (see for example [1]). If you are using TFS 2008 or earlier, this can be achieved using a "Pre-Build Event," as documented for the Resource.Designer.cs file here: http://developer.xamarin.com/guides/cross-platform/ci/tfs_walkthrough/#Prepare_Xamarin.Android_for_TFS. If you are using TFS 2013, you can use a script similar to Alfonsi's suggestion below as a Pre-build PowerShell script.

Workaround possibility 3: downgrade to Xamarin 3.6.262 (Windows) or Xamarin.Android 4.16.0.17 (Mac) or earlier

Windows

  1. Downgrade to Xamarin 3.6.262 (or earlier) for Windows:
    http://download.xamarin.com/XamarinforVisualStudio/Windows/Xamarin.VisualStudio_Setup-3.6.262.msi

  2. If you use Xamarin.iOS, download this corrected .targets file: https://s3.amazonaws.com/xvs.xamarin.com/Xamarin.iOS.Common.targets. (Steps 2 and 3 are needed to work around a bug in 3.6.262).

  3. Copy the file into C:\Program Files (x86)\MSBuild\Xamarin\iOS, overwriting the existing file. (This step requires administrator privileges.)

  4. If you use Xamarin.iOS, you'll also need to downgrade the Mac build host to the matching version:
    http://download.xamarin.com/MonoTouch/Mac/monotouch-8.0.0.63.pkg

Mac

  1. Downgrade to Xamarin.Android 4.16.0.17 or earlier:
    http://download.xamarin.com/MonoforAndroid/Mac/mono-android-4.16.0-17.pkg

Build error

// 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

Note about QA testing for this particular issue

At present, TFS is not included in Xamarin's stable release testing process. If you'd like to see this added as part of the testing process we'd highly recommend voting for it on Xamarin's UserVoice. In the absence of data about the number of users who need regression testing for TFS, plans to add TFS to the testing regimen will have to wait until Xamarin has grown to have some extra testing capacity. If TFS regression testing shows up as a highly demanded suggestion on UserVoice, it can be added to the testing regimen sooner.


EDIT October 8: Updated the workarounds a little based on the comments. Added a note about QA testing.
EDIT October 8: Added pre-build / post-build events suggestion to workaround 2.
EDIT October 16: Update to mention the Xamarin 3.7.226 hotfix build. Update workarounds and a distinction between TFS build agent builds and local "direct" builds.
EDIT October 30: New complete fix is now in the stable channel.

«1

Posts

  • whitetwhitet USMember
    edited October 2014

    Downgrading was the only solution that worked for us.

    Rebuilding the project will never work, because the files are copied as read-only even when they're checked out in TFS.

  • I am having a problem with this as well -- although I am using Sourcegear Vault 7+ instead of TFS. None of the above solutions work as stated by @whitet.

    Instead of downgrading, I will just work on another portion of the app until an update is available.

    Thanks,
    Timothy

  • CarelLotzCarelLotz ZAMember ✭✭

    What worked for us (we are using TFS) is to first delete the obj\bin folders containing the readonly versions of the files, then recursively check out the Resources folder. When you recompile everything should work fine. Not ideal, but downgrading is just too intrusive as this stage for us.

  • whitetwhitet USMember

    Couldn't have said it better myself @Woody. We have also run into issues every time we update. Our team is now nervous to update to new 'stable' versions, it shouldn't be like that.

    The latest actual stable version shouldn't be from almost 4 months ago. :/

  • nkuznetsovnkuznetsov USMember
    edited October 2014

    Checking out whole resources folder, deleting obj/bin folders, and rebuilding worked for me. I.e. @CarelLotz method, more or less.

    Update: this method actually stopped custom controls from working for some reason. Layouts containing custom controls no longer inflate. Sigh, will try downgrading.

  • PaulyPauly USMember ✭✭

    This is bad. Needs fixed ASAP.

  • Woody712Woody712 GBMember ✭✭

    I'd like to vote for this QA UserVoice topic but I get 'We couldn't submit your vote at this time.' Presumably this voting system is under TFS also..... {rolling eyes}

  • ludwoludwo USMember

    It is still not working in 3.8.13.0 (Beta). I thought it will be solved in 3.8 :(

  • jdevxjdevx USMember
    edited October 2014

    We are also spending more time troubleshooting Xamarin issues than we are actually building our app. Every update poses new problems like this and it's now to the point where we're all afraid to update our install. In our case the fix is to manually set the resources folder to non-readonly.

  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai
    edited October 2014

    @Woody‌, thanks for reporting the issue with voting on UserVoice! If you're still seeing that problem, then I think we'd be interested in the account details you're using to try to vote, so we can get in touch with UserVoice about the problem. You can message them to me, or send them to [email protected] I was able to vote using both Google OpenID authentication and a plain non-Xamarin email address. Thanks!

    @all, anyone is welcome to create new UserVoice suggestions on http://xamarin.uservoice.com/. So please do create new suggestions if there are broader issues that you'd like to see addressed in Xamarin's overall release strategy beyond basic TFS regression testing.

  • JasonEstesJasonEstes USMember

    This issue is not related to TFS in particular. Any source control system that marks files as read-only on the local machine when they are checked in will have this issue. Considering the price of this product, I have to assume it is used an an enterprise environment almost exclusively. That tells me that of the projects where Xamarin is used, 99.9999% will also use some sort of source control and a portion of that will be TFS, as evident by the flaming posts above.

    How hard is it to clear a read-only attribute on a file you just made a copy of? Since we all know it's not difficult, how long can it take to get a fix?

  • softlionsoftlion FRBeta ✭✭✭

    Checking out whole resources folder, then deleting obj/bin folders and rebuilding also worked for me.

    @nkuznetsov‌ custom controls still works for me. Should not be the same issue.

  • AlfonsiAlfonsi USMember ✭✭✭
    edited October 2014

    WA 2 Powershell solution:

    $projectPath = "c:\Dev\Project"
    
    cd "$projectPath/obj"
    rm -fr Debug
    
    cd "$projectPath/Resources"
    gci -Recurse | %{ if($_.IsReadOnly) {$_.IsReadOnly = $false} }
    

    and build..

  • RyanHatfieldOldRyanHatfieldOld USMember, Insider ✭✭✭

    I Had this problem while at Xamarin Evolve and @JonathanPryor came over to look at it and for the life of me I could not reproduce the error. I'm glad it's fixed now though, cause when I reconnect my project to TFS it 'read-only's the files again. It looks like it's fixed now:

    " Fixed in monodroid/41c7adf7 and monodroid-4.18-series/186c6bf7. "

  • Woody712Woody712 GBMember ✭✭

    @RyanHatfield‌ Is it fixed? I'm still on the old version. From what I can see it's we are still on the same Stable, Beta and Alpha releases there was a few days ago. Clicking on the release notes (in VS) for beta channel just opens up 15 tabs of "http://developer.xamarin.com/releases/vs/xamarin.vs_3/xamarin.vs_3.8/" with file not found. Another bug...

  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai
    edited October 2014

    Ryan is correct that a fix has been applied to the development branch, but that hotfix build has not yet been released. It is still undergoing some testing by the QA team (mostly to ensure that the bugs that are supposed to be fixed do indeed pass the new tests).

    Just to clarify again briefly (and at the risk of being redundant), the comparatively slow timeline to release a fix for this particular bug is largely due to the fact that the development team was busy interacting with attendees and giving presentations at Xamarin's Evolve conference last week. The developers see this as a high priority bug, and they are in favor of adding basic regression testing for TFS to the stable release process so that problems like this don't resurface in the future.

  • RyanHatfieldOldRyanHatfieldOld USMember, Insider ✭✭✭

    here here @BrendanZagaeski‌ ... this is a regression issue so it's good they're adding the tests.

    Currently I suggest the pre-build options listed in your original post, otherwise just check out the entire resources file and delete the bin / obj folders if you have an issue. To make that even better, you could make a pre-build to check out the resources folder.

  • @BrendanZagaeski‌ is this going to be put in Beta stream as well?

  • JoeRock11JoeRock11 USMember

    Any idea when the update for the fix is going to hit? Ran into this problem this morning.....(why did I update)....

  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai
    edited October 2014

    The Xamarin 3.7.226 hotfix release that was just published to the stable channel will hopefully solve this issue for all Windows users. Refer to the updated first post in the thread for a few more details.

    @JonathanChapman‌, the fix will be included in the next beta release too. I think there will be another beta release sometime next week, if all goes to plan.

  • I switched back to stable, upgraded, and still get the error message. Anything else required?

  • JoeRock11JoeRock11 USMember

    @BrendanZagaeski‌ Thank you for keeping us up to date!

  • JoeRock11JoeRock11 USMember

    Darn I feel you @JonathanChapman‌ still the same exact error after updating to 3.7.226, anybody got any ideas?

  • Try manually setting the folders back to read/write and then building again.

  • JoeRock11JoeRock11 USMember

    Just for reference, here is the error....

    Error 2 The "CopyAndConvertResources" task failed unexpectedly.
    System.UnauthorizedAccessException: Access to the path 'C:\code\AL_MobileGrower\AL_MobileGrower\ALMG_Android\obj\Debug\res\layout\login.xml.tmp' is denied.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.File.InternalDelete(String path, Boolean checkHost)
    at System.IO.File.Delete(String path)
    at Xamarin.Android.Tasks.CopyAndConvertResources.Execute()
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() ALMG_Android

  • JoeRock11JoeRock11 USMember

    Thank you @EugenePinskiy‌ this was half of the problem. Disabling the read-only flag alone was not enough, after doing this I also had to delete the obj folder within my projects directory (probably because of cached temp files) and boom everything worked! Thanks again I hope this helps others...

  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai

    Shoot. Many thanks for the follow-up Joseph and Jonathan, and especially thanks for the new error message Joseph.

    Unfortunately the first test case I created for the bug report was foolishly not aggressive enough. I was basing the test case off the steps in another bug report, so it didn't cross my mind that there would be an important distinction between marking the whole Resources\ folder read-only compared to just a few specific resources.

    I've re-opened the bug report with a better test case and directly notified the developers about the remaining problem with the *.xml.tmp files. Hopefully we can get a follow-up fix for this issue released very soon.

  • Yes I still get this and it been a pain in the***. If I can do anything to help get it resolved please let me know.

  • MattZamoraMattZamora USMember

    Can we get a status update on the progress of the fix for the issue? It's a major hindrance to development. While I totally understand these things happen it would be nice to know how much longer we need to live with the workarounds.

  • Woody712Woody712 GBMember ✭✭

    I'm sure there is another pressing cosmetic IOS release that needs to take priority over bug fixing android platform.

  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai
    edited October 2014

    Hi all, I'm working on getting you an update about a fixed build. The Xamarin.Android hotfix release process has unfortunately become quite complicated recently due to:

    That said, the Xamarin.Android team does already have a patch to fix the remaining read-only resources issue, and I've asked the developers if we can get a candidate build for you guys that includes the patch, similar to what we just did for the Yosemite Mac build host pairing issue.

    Just in case it might be helpful to know, the Android team is independent of the iOS team, so delays on Android are unrelated to any work that's happening on iOS.

  • I am hit by this as well. Nothing I do makes the read only flag go away on "Resources". Posting in hopes to get followups.

  • I downgraded and now I get this error (somewhat redacted)

    Error 1 The "RemoveUnknownFiles" task failed unexpectedly.
    System.UnauthorizedAccessException: Access to the path 'C:... \projectname...\obj\Debug\res\layout-sw600dp-land\activity_main_menu.xml.tmp' is denied.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.File.InternalDelete(String path, Boolean checkHost)
    at System.IO.File.Delete(String path)
    at Xamarin.Android.Tasks.RemoveUnknownFiles.Execute()
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() MyApp

  • I reverted back to latest xamarin as rolling back did not help. I tried running the nice powershell script provided here and also visual studio as administrator but the error persists.

  • RyanHatfieldOldRyanHatfieldOld USMember, Insider ✭✭✭

    @RobertCastles‌ did you COMPLETELY delete the bin and obj folders? not just clean.

  • Apparently not. This time, I double checked with explorer, checked my Resources folder in and back out, and I can build.

    Thanks!

  • KarimJouiniKarimJouini FRMember

    I am hit by this as well, I had to disable my Xamarin.Android app from the build. Looking forward for the fix!

  • KarimJouiniKarimJouini FRMember

    No update? This is really a painful blocker :( ...

This discussion has been closed.