locked
Moving a StorageFile throws COMException

    Question

  • Hi all!

    I am developing an Windows 8.1 app, which interacts with Windows filesystem and all folders are correctly added to FutureAccessList.

    I am copying a StorageFile to some folder like this:

    await file.CopyAsync(destinationFolder, newFileName, NameCollisionOption.ReplaceExisting);

    Then I am trying to move exactly the same file with exactly the same name into exactly the same folder (after a while and in another method) like this:

    await file.MoveAsync(destinationFolder, newFileName, NameCollisionOption.ReplaceExisting);
    This method raises following COMException:
    Error HRESULT E_FAIL has been returned from a call to a COM component.
    I have no clue why this takes place, except some kind of bug in CopyAsync internally, maybe, that method doesn't release the copy or somewhat else. Please, describe this strange behavior.



    Saturday, January 17, 2015 11:16 AM

Answers

  • Hi Zolotaryov,

    Thanks for your confirmation, however due to the policy, I cannot leave my mail with you, anyway share your sample project with communities will also involve communities help you.

    I would like to know following questions for a self test:

    #1, Where is your file located? And how you get the file token?

    If your file is saved somewhere need to open by fileopenpicker, probably you only save the file access permission to the FutureAccessList, but not the folder, that could be a possibility.

    #2, Did you have other application access to the file at the same time or did you have some thread access to the file when you want to move it?

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 26, 2015 9:25 AM
    Moderator

All replies

  • Hi Zolotaryov,

    Any more information you can provide to us?  COMException seems too less without any helpful information.

    Did you try if you move the file directly without copy the file, will the COMException thrown, probably the reason is like you mentioned, the file is locked somewhere in the app. You may also test with Delete the file.

    Anyway move can be treat as copy the file to the destination folder and delete the file from original folder, if you need a quick workaround, you can use this.  I would also recommend you share your project with me for a better analysis if you confirm the file is not locked by the app, probably some other part of the code goes wrong.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 19, 2015 6:09 AM
    Moderator
  • COMException seems too less without any helpful information.

    That's the reason of my question ;)

    However, this exception appears ONLY after moving a file. E.g. I have a file A.txt and move it to a folder F. After it has been moved correctly, I am copying or moving again a file A.txt into the same folder F -> exception. I checked all the ways the file passes through, though I found no additional locks.
    I am quite sorry, but I can't share my project, because it's NDA.

    I'll try to build a sample and share it with you. Please, leave your e-mail :)

    Tuesday, January 20, 2015 9:51 AM
  • Hi Zolotaryov,

    Thanks for your confirmation, however due to the policy, I cannot leave my mail with you, anyway share your sample project with communities will also involve communities help you.

    I would like to know following questions for a self test:

    #1, Where is your file located? And how you get the file token?

    If your file is saved somewhere need to open by fileopenpicker, probably you only save the file access permission to the FutureAccessList, but not the folder, that could be a possibility.

    #2, Did you have other application access to the file at the same time or did you have some thread access to the file when you want to move it?

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 26, 2015 9:25 AM
    Moderator
  • #1. My file is located in another folder. The folder is already added to FutureAccessList.
    #2. I have checked thread access of this file - it is crystal clear.
    Big, big thanks for a thoughts about FutureAccessList of FILES. Just added a new file (returned after copy) to FAS and now moving the same file into the same location seems to work as needed.
    Problem solved.
    Monday, January 26, 2015 5:22 PM