I am trying to download some BitmapImages files from files stored in the file system. I have a dictionary of keys and relative file paths. Unfortunately, the Uri constructor seems non-deterministic in how it will load 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 Uris loads as a relative Uris file, and sometimes they load as a relative Uris Pack. There seems to be no rhyme or reason why it will load that way. Sometimes I get the entire Uris download in one direction, or just a couple or most of them, and every time I run the code, it will change.
Any ideas on what's going on here?
source share