StorageApplicationPermissions.FutureAccessList.Entries throwing FileNotFoundException (UWP)

asked 2021-10-17T23:47:58.89+00:00
Adam Leibhardt 96 Reputation points

I have a UWP app that i'm seeing rare logs where FutureAccessList.Entrise is throwing a FileNotFoundException. From the logs i've been able to track down the exception to being thrown at this line:

var accessList = StorageApplicationPermissions.FutureAccessList.Entries

This is the relevant part of the callstack that I'm getting from the logs:

System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
at System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x20
at __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32, Void*) + 0xbe
at __Interop.ForwardComStubs.Stub_3TThis, TResult + 0x37
at Drawboard.Services.FileSystemService.CleanseFutureAccessList(IList`1) + 0x66

This is only happening to a very small percentage of our userbase, however when it does hit, the application becomes unsuable.
Right now, the only mitigation I have for users is to tell them to reinstall the application, which seems to resolve the issue most of the time.

Looking at the documentation, there is no reason that I could see that would cause this exception to be thrown.

Does anyone have any idea what is going on here? For now, I can at least detect this case, and put a prompt up to the user suggesting they reinstall the app, but obviously this is just a temporary stop gap, and it would be great to be able to solve this problem without needing the user to perform a reinstall.

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. answered 2021-10-21T03:00:38.767+00:00
    Adam Leibhardt 96 Reputation points

    I have found a workaround for this issue.

    My solution is to call the following line:

    StorageApplicationPermissions.FutureAccessList.Clear()
    

    This function works and clears the future access list completely, deleting the corrupt registry key in the process allowing the rest of the methods to work.

    The problem with calling this though is that it removes all of my access to any files that i have saved in the future access list. For my application, this means that the next time a user tries to save a file, they end up being prompted again with a file picker to save the file to a location (kind of a forced save as).

    Fortunately, I'm able to completely work around this shortcoming. Our application caches all the tokens in the FutureAccessList for our own purposes. By using this cache, i'm able to call into:

    StorageApplicationPermissions.FutureAccessList.GetItemAsync(token)
    

    Before clearing my list, i load all cached IDirectoryItems into memory.
    Now I can clear my list without losing access to any of my files.

    After clearing the list, I can go through and add each item back into the FutureAccessList.

    Then I simply need to go back through my cache, and update my source tokens with the new tokens and I'm back into a stable state, without losing any future access list.

    Note i do think there is something funny going on in the platform here, and somehow the registry is getting corrupted (lastUpdatedTime being deleted), but I can make progress for now.

    No comments

0 additional answers

Sort by: Most helpful