Search Unity

HoloLens 2 // External File Access // IL2CPP // UWP

Discussion in 'Editor & General Support' started by jehbediah, Aug 31, 2020.

  1. jehbediah

    jehbediah

    Joined:
    Aug 7, 2020
    Posts:
    3
    Hello,

    We have a HoloLens 2 device that is plugged into a Windows 10 computer. We are trying to access a file that resides on the Windows computer, from the HoloLens device.

    This project configuration is below:
    Scripting Backend: IL2CPP
    API Compatability: .NET 4.x
    C++ Compiler Config: Release

    We have tried an abhorrent number of combinations to get this working, but have come up short. Even going so far as downgrading Unity to 2018.x so that we can use the .NET scripting backend in hopes of more / different capabilities.

    Our current dilemma is this:
    • The UWP for HoloLens app builds and deploys to the HoloLens.
    • The value of tmpText.text is not updated.
    • No errors shown in Unity console.
    • Errors are only visible once surrounding the code in a try/catch and logging.
    • The exception is included at the very bottom of this post.
    We've added broadFileSystemAccess, tried using FilePickers, and about anything else we could think of, short of setting up a server that both machines communicate to. Any and all help would be appreciated.

    Code snippets:
    Code (CSharp):
    1.  
    2. // Start is called before the first frame update
    3.     void Start()
    4.     {
    5.         try
    6.         {
    7.  
    8. #if ENABLE_WINMD_SUPPORT
    9.  
    10.             FileOpen_Click(@"C:/Users/VR_5/Pictures/Image.png");
    11.  
    12. #endif
    13.  
    14.         }
    15.         catch (Exception ex)
    16.         {
    17.             tmpText.text = ex.ToString();
    18.         }
    19.  
    20.     }
    21.  
    22. private void FileOpen_Click(string targetFilePath)
    23.     {
    24.         // 1. Display file path in UI.
    25.         tmpText.text = targetFilePath;
    26.  
    27.         // 2. Open the file at the target path.
    28.         BroadFileOpen(targetFilePath);
    29.     }
    30.  
    31.     private async void BroadFileOpen(string targetFilePath)
    32.     {
    33.         // it's normally used to allow the user to opt in to access a file once, then automatically allow them to continue to access it'
    34.         // https://docs.microsoft.com/en-us/uwp/api/windows.storage.accesscache.storageapplicationpermissions.futureaccesslist?view=winrt-19041#Windows_Storage_AccessCache_StorageApplicationPermissions_FutureAccessList
    35.         // https://forum.unity.com/threads/external-file-access-on-wsa-il2cpp-build.663523/
    36.  
    37.         try
    38.         {
    39.  
    40. #if ENABLE_WINMD_SUPPORT
    41.  
    42.             // ERROR: THE APP FAILS HERE AND THROWS THE EXCEPTION LISTED!
    43.             var file = await Windows.Storage.StorageFile.GetFileFromPathAsync(targetFilePath);
    44.            
    45.             string text = await Windows.Storage.FileIO.ReadTextAsync(file);
    46.            
    47.             tmpText.text = text;
    48.  
    49. #endif
    50.         }
    51.         catch (Exception e)
    52.         {
    53.             tmpText.text = e.ToString();
    54.             CreateDebugFile(e.ToString());
    55.         }
    56.     }
    Exception:
    System.Exception: Exception of type 'System.Exception' was thrown.
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
    at System.Runtime.CompilerServices.ConditionalWeakTable`2[TKey,TValue]..ctor () [0x00000] in <00000000000000000000000000000000>:0
    at ToggleTableManipulation.ToggleHandler (Microsoft.MixedReality.Toolkit.UI.ManipulationHandler mManipulationHandler) [0x00000] in <00000000000000000000000000000000>:0
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in <00000000000000000000000000000000>:0
    at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.Experimental.LowLevel.PlayerLoopSystem+UpdateFunction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.WSA.WindowSizeChanged.BeginInvoke (System.Int32 width, System.Int32 height, System.AsyncCallback callback, System.Object object) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00000] in <00000000000000000000000000000000>:0
     
  2. jehbediah

    jehbediah

    Joined:
    Aug 7, 2020
    Posts:
    3
    I figured it out. You just need to avoid using Unity entirely I think
     
  3. maturski62

    maturski62

    Joined:
    Jan 22, 2019
    Posts:
    3
    That doesn't seem like an optimum solution in the long run. Unfortunately, I do not have the answer to this, but I'm sure it would take someone with great intelligence to figure this out. Hopefully that someone sees this soon though!
     
    Eltanin9 likes this.
  4. gosselinsimon713

    gosselinsimon713

    Joined:
    Sep 3, 2020
    Posts:
    2
    I got it to work, but I didn't use UWP or the Hololens. I used Android and the Oculus Quest instead and it worked fine!
     
  5. Eltanin9

    Eltanin9

    Joined:
    Mar 7, 2019
    Posts:
    5
    I've also been wondering if this is possible. I'd like to find an answer for this. You'd be able to do some pretty interesting things if it is possible. And if not, Microsoft needs to step up their game
     
  6. maturski62

    maturski62

    Joined:
    Jan 22, 2019
    Posts:
    3
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I'm not sure what the expectation is here. The code posted above is trying to access the file that's stored locally. That means that if the app is running on HoloLens, the code will look for the file on HoloLens (which I assume isn't there).

    I'm not even sure why you're saying that avoiding using Unity fixes the issue: the issue isn't in Unity. It's in the code you wrote. You're going through Windows APIs so Unity isn't even involved in here. That code will not work regardless of what framework you use to render your app.

    How do you even expect to access the filesystem of the Windows computer from HoloLens?
     
  8. jehbediah

    jehbediah

    Joined:
    Aug 7, 2020
    Posts:
    3
    @Tautvydas-Zilys
    That's why I posted this question. It's a requirement that was given. Obviously a potential solution involves using a server to act as a middle man between the HL2, but that would require either an internet connection or a local server. For my requirements, the local server will work but is undesirable so I posted this question. I figured I would ask since I read that you can access files on the Windows device from the HL2, albeit only limited directories, but maybe those were incorrect.

    PS - As for the unity jab in my response, it wasn't due to something in this post specifically, mostly my disappointment in Unity overall. Mainly having hit limitations surrounding the DataReceived event implementation, or lack thereof in Mono, as well as the platform dropping the .NET backend for Mono. Additionally, I've run into limitations with EFCore (can't recall exactly but maybe due to AOT or something) that required a re-work. For context, I'm not a Unity dev, so I only have to interact with it sparingly, and every time I do I run into limitations that require workarounds or re-designing the system.
     
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    What/where did you read about it? I assume if you share the folders in Windows and HoloLens in on a local network, you can access it like a shared folder via SMB but there will always be networking involved. AFAIK, HoloLens doesn't magically gain access to your computer filesystem if it's hooked up via USB (since that would be a huge security hole).