Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:35:47+00:00 2026-06-13T05:35:47+00:00

Below is the code I used to access the asset file for a metro

  • 0

Below is the code I used to access the asset file for a metro app I am working on.

        async void readFileFromDisk (string fileName, string fileType)
    {
        string fileContent;

        StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileName);
        using (IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read))
        {
            using (DataReader dataReader = new DataReader(readStream))
            {
                UInt32 numBytesLoaded = await dataReader.LoadAsync((UInt32)readStream.Size);
                fileContent = dataReader.ReadString(numBytesLoaded);
            }
        }

This code is run in the handler for Loaded event for the page. I am currently getting an exception saying “Value does not fall in range”. The error occurs at the first line itself, where I try to get storagefile handle from the installation folder.

On debugging, the fileName string comes out to be Null. I guess, I should be moving the code to some event which is fired at a later stage in page lifecycle, but can’t seem to figure out what is the best place to do it. Suggestions??

P.S. I need to read this file before any interaction from user, as it reads the data for the level, that user will be interacting with.

Edit:

Missed a couple things.
The below function is called from the handler for loaded event.

void Game_Loaded(object sender, RoutedEventArgs e)
    {
        //read all level files to the strings
        readFileFromDisk("//Assets/Levels/Start" + selectedLevel + ".txt", "Start");

This handler basically calls above function for different file paths, in similar manner. The string selected level is static variable, while the fileName string is created from the same.

Edit 2:

Found the issue, but solution is still far away. The return type of readFileFromDist method is causing trouble. Changed it to Task, and this part works fine, but I get “Object reference not set to an instance” error. Tried to convert Game_Loaded event handler to async too, to use await operators, but that gives me compiler error for “wrong return type”.

SO, I tried removing async completely, but I guess I can’t do that. There is no way to open files without using async function. So, I essentially need a way to call the readFileFromDisk function, using await, and continue with rest of the code execution once the task is completed. Something like, “IsCompleted” event for the awaited calls for the function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:35:48+00:00Added an answer on June 13, 2026 at 5:35 am

    Solved! Needed to use “ms:appx///Assets/filename.txt” instead of “//Assets/filename.txt”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the below code to open an Excel file in MS Access
I have used the below code to access iframe contents but it is not
I have used below code to attach quckboook events // Subscribe to UI events...
Code below is used to save PostgreSql database backup from browser in Apache Mono
I had used the below code to get the row index of the UIPickerView
My below code works fine and is used to populate a <select> item with
I have used the code below to read rfid tag values. try { if
I am having a very specific problem in JQuery The code below is used
Little trouble in using css, in the below code, i have used odd and
I have some problem with my cfml website. I have used the below code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.