Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality. If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers. And always feel free to hit us up on Twitter @MxdRealityDev.

Unity - FileOpenPicker causes crash

In my hololens application I am trying to load a single file from onedrive. I tried to use the fileopenpicker however when I deploy my app to hololens and call the OpenFileAsync function as UnityEngine.WSA.Application.InvokeOnUIThread(()=> OpenFileAsync(), false); my app crashes and Visual Studio gives 0xc000027b error code. I tried many samples on the internet yet non of them did work. I don't know what I'm missing. Any help would be appreciated. Here is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Diagnostics;
 using System.Runtime.CompilerServices;
 using System.Threading;
 using System.Threading.Tasks;
 using System;
 using UnityEngine.WSA;
 using UnityEngine.UI;

 #if ENABLE_WINMD_SUPPORT
     using Windows.Storage;
     using Windows.Storage.Streams;
     using Windows.Storage.Pickers;
 #endif

 public class GetFile : MonoBehaviour
 {
     public TextMesh label;

 #if !UNITY_EDITOR
         private FileOpenPicker openPicker;
 #endif


     public void CallFile()
     {
 #if !UNITY_EDITOR
         UnityEngine.WSA.Application.InvokeOnUIThread(()=> OpenFileAsync(), false);
 #endif
     }



 #if !UNITY_EDITOR
     private async void OpenFileAsync()
     {
         FileOpenPicker openPicker = new FileOpenPicker();
         openPicker.ViewMode = PickerViewMode.Thumbnail;
         openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
         openPicker.FileTypeFilter.Add(".txt");

         StorageFile file = await openPicker.PickSingleFileAsync();
         if (file != null)
         {
             // Application now has read/write access to the file
             label.text = "find";
         }
         else
         {
             label.text = "nope";
         }
     }
 #endif
 }
Tagged:

Best Answer

Answers

  • It may be worth upgrading to RS5 and checking out how they do the file picker without leaving the app:
    https://forums.hololens.com/discussion/10872/announcing-hololens-preview-17720#latest

    Taqtile

  • Thanks for your answer. Turning on the pictureslibrary capability and changing the suggested start location to pictureslibrary did the job. However it's not clear how to give permisssion access to -for example- documents folder. Its weird that I can start from the pictures folder and navigate back to where I want but when I want to directly go to the folder I want, the app just crashes and I can't catch the error even with try-catch block.

Sign In or Register to comment.