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

  • Home
  • SEARCH
  • 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 4382298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:45:41+00:00 2026-05-21T12:45:41+00:00

I am trying to load some BitmapImages from files held on the file system.

  • 0

I am trying to load some BitmapImages from files held on the file system. I have a dictionary of keys and relative filepaths. Unfortunately the Uri constructor seems non deterministic in the way that it will load the images.

Here is my code:

foreach(KeyValuePair<string, string> imageLocation in _imageLocations)
{
    try
    {
        BitmapImage img = new BitmapImage();
        img.BeginInit();
        img.UriSource = new Uri(@imageLocation.Value, UriKind.Relative);

        img.EndInit();
        _images.Add(imageLocation.Key, img);
    }
    catch (Exception ex)
    {
        logger.Error("Error attempting to load image", ex);

    }
}

Unfortunately sometimes the Uris get loaded as relative file Uris and sometimes they get loaded as relative Pack Uris. There doesn’t seem to be any rhyme or reason as to which will get loaded which way. Sometimes I get all the Uris loading one way, or just a couple, or most of them, and it will change each time I run the code.

Any ideas what is going on here?

  • 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-05-21T12:45:41+00:00Added an answer on May 21, 2026 at 12:45 pm

    Well, sort of… MSDN has this to say about the UriKind:

    Absolute URIs are characterized by a complete reference to the resource (example: http://www.contoso.com/index.html), while a relative Uri depends on a previously defined base URI (example: /index.html)

    If you jump into reflector and look around you can see that there are lots of paths for the code to take to resolve what the relative URI should be. Anyhow, it isn’t that its non-deterministic, it’s more that it is just a major source of frustration for many developers. One thing that you can do is emply the ‘BaseUriHelper‘ class to get to the bottom of how your uris are being resolved.

    On the other hand, if you know where your resources are being stored (and you should) I would suggest that you just spare yourself the headache and use an absolute URI to resolve your resources. Works every time, and no goofy code behind the scenes to trip you up when you least expect it.

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

Sidebar

Related Questions

I am trying to load some info from the database asynchronously. I have a
I'm trying to load some decimal values from a file but I can't work
So I'm trying to load some returned html from an .aspx page but a
In the NodeMouseClick event I'm trying to load some objects from the Node.Tag. Before
I am am trying to load a SQL table from a flat file. The
I'm trying to load some data via. jquery $get_desc = SELECT tekst_id,overskrift FROM rr_tekster
I'm trying to load some ajax content into a table, unfortunately it's only loading
I am currently trying to load some js files asynchronously, so that they are
In the code below I'm trying to load some images and put them in
I'm trying to call a function after I load some XML into Actionscript, and

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.