URI correct but incorrect at run-time?

0

My file, located at 'C:/Users/Username/Desktop/sample.pdf' is there. I can open it manually and it loads fine. Now if I put an invalid link, such as, file:///sample.pdf, which clearly can't be found, the Hololens app will open the Edge browser attempting to open the pdf. So, it's clear the code is functioning.

So why then is this uri incorrect when loading in the Hololens at run-time?

    string uriToLaunch = "file:///C:/Users/Username/Desktop/sample.pdf";

    // Create a Uri object from a URI string 
    var uri = new Uri(uriToLaunch);

    Task task = new Task(

        async () =>
        {
            // Launch the URI
            var success = await Windows.System.Launcher.LaunchUriAsync(uri);

            if (success)
            {
                // URI launched
            }
            else
            {
                // URI launch failed
            }
        });

    task.Start();
    task.Wait();

Here is the exception thrown.

Exception thrown: 'System.ArgumentException' in Assembly-CSharp.dll

WinRT information: The provided URI scheme can't be launched. Unhandled 'Platform.InvalidArgumentException' exception caught! - 'The parameter is incorrect.'

The parameter is incorrect. The provided URI scheme can't be launched.', Sender: 'null'. Missing try/catch blocks.

The tricky thing with these exceptions in the Hololens is sometimes they don't seem to be related to whats not working. I've tried googling the error and nothing helpful appears.

EDIT: string uriToLaunch = @"file:///Data/myFiles/sample.pdf"; returns WinRT information: The provided URI scheme can't be launched. The parameter is incorrect.

string uriToLaunch = @"/Data/myFiles/sample.pdf"; returns UriFormatException: Invalid URI: The format of the URI could not be determined.

NOTE I thought I could open the Edge browser from the app but I'm having trouble replicating this functionality. The only thing that responds, positively, shall we say, is

@"ms-appx:///Data/myFiles/sample.pdf";

This opens up a separate dialog box that will take my to the MS store to try and buy an app that will open ms-appx files.

EDIT 2:

    FileOpenPicker openPicker = new FileOpenPicker();
    openPicker.ViewMode = PickerViewMode.Thumbnail;
    openPicker.ViewMode = PickerViewMode.Thumbnail;
    openPicker.FileTypeFilter.Add(".jpg");
    openPicker.FileTypeFilter.Add(".jpeg");
    openPicker.FileTypeFilter.Add(".png");

    Task task = new Task(
    async () =>
    {
        StorageFile file = await openPicker.PickSingleFileAsync();
        if (file != null)
        {
            // Application now has read/write access to the picked file
            Debug.Log("Picked photo: " + file.Name);
        }
        else
        {
            Debug.Log("Cancelled");
        }
    });

    task.Start();
    task.Wait();

I've tried implementing this simple FileOpenPicker, just to test and see if I could get one working, to no success.

It throws this:

Exception thrown: 'System.Exception' in mscorlib.ni.dll

Unhandled 'Platform.COMException' exception caught! - 'Invalid window handle.

EDIT 3: This is all I can find on the error.

COMException If the ErrorCode property of the exception has the value 0x80070578 (ERROR_INVALID_WINDOW_HANDLE), this indicates that the method was not called on the UI thread.

EDIT 4: Now it's crashing and returning:

Exception thrown: 'System.Exception' in mscorlib.ni.dll

The program '[4084] hololensapplication.exe' has exited with code -1073741189 (0xc000027b).

c#
uwp
windows-runtime
uri
hololens
asked on Stack Overflow Jun 29, 2017 by jtth • edited Jun 29, 2017 by jtth

1 Answer

0

As @AVK points out, UWP apps are sandboxed. This means files outside of the Hololens local environment aren't reachable. There are local known folders on the HoloLens, but the only way to get around this is to use third party apps such as OneDrive, Azure, etc.

answered on Stack Overflow Jul 7, 2017 by jtth • edited May 10, 2018 by jtth

User contributions licensed under CC BY-SA 3.0