Search Unity

Potential bug when reading files from path in UWP with IL2CPP backend vs .NET backend

Discussion in 'Windows' started by sharkweek42, Mar 6, 2019.

  1. sharkweek42

    sharkweek42

    Joined:
    Jul 30, 2013
    Posts:
    14
    I am currently attempting to update our UWP project from .NET to IL2CPP in Unity 2018.3.6f1. I think I've found a bug, but I'd like to run it by other people before I file a bug report. Apologies for not including any code; this functionality is split up among 4 or 5 different classes, but I'm sure I could condense it into a minimum repro project if necessary. Anyways, here goes:

    Our app needs to read all of the files in a folder and do some processing with the data obtained from the files. Previously we would use the FolderPicker from Windows.Storage.Pickers to allow the user to select a StorageFolder. Then we add the selected folder to the FutureAccessList in Windows.Storage.AccessCache.StorageApplicationPermissions. We extract the file paths from all StorageFiles in the selected StorageFolder and open FileStreams directly from the paths. We use a similar process for when the user needs to open a single file, except with a FilePicker instead of a FolderPicker. Using the paths is convenient because it (sorta) works on every platform.

    Unfortunately this process does not work in IL2CPP at all. In fact it seems that you cannot open a FileStream from a path in IL2CPP, even if the files are in the Pictures folder and the app is given access to the PicturesLibrary. Every attempt throws a DirectoryNotFoundException: Could not find part of the file path, which seems incredibly weird since I'm not modifying the paths after I get them from the StorageFiles. I can, however, use StorageFile.OpenReadAsync to get an IRandomAccessStreamWithContentType, then I can use the AsStreamForRead extension method to turn that into a regular Stream to read the data in the file. This process is a bit awkward and would require a major refactor for our file import code, so I'd rather stick with the old method if possible.

    I'm not sure where to go from here. I see three possibilities:

    1) This is a bug. I don't see anything similar in the issue tracker, so I could definitely file a bug report with a minimum reproducible project.

    2) This hasn't been implemented in IL2CPP yet. Seems unlikely, but I imagine there aren't a lot of Unity apps that do what we are doing, so it could have been missed.

    3) I'm doing something wrong. This is also possible because I don't have a lot of experience with UWP apps outside Unity.

    Any suggestions?
     
  2. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    67
    Hi,

    FileStream is available in IL2CPP, and the DirectoryNotFound exception does indicate this is probably a bug. So please go ahead and file a bug report.

    In general, the IL2CPP limitations only apply to the .NET APIs available in the scripting back-end. However, platform specific APIs, e.g. StorageFile.OpenReadAsync(), are not impacted by IL2CPP.