Why can't this jpg resource in be found within its own library?

1

Doing some refactoring of some projects and I'm running into a resource issue that has me stumped. I'm having trouble loading resources from within a library. The same code runs fine within the main app (if I move the resource there of course.)

Here's the app version that works...

MyApp.csproj
 - Resources
    - Images
       SomeFile.jpg <-- Set to 'Resource' in the properties grid

I then have the following code running in the app which works fine.

var imageSourceConverter = new ImageSourceConverter();
var packUriString = $"pack://application:,,,/Resources/Images/SomeFile.jpg";
someImage.Source = imageSourceConverter.ConvertFromString(packUriString) as ImageSource;

I then try to move both this code and the resource to a new library 'MyLibrary', like so...

MyLibrary.csproj
 - Resources
    - Images
       SomeFile.jpg <-- Set to 'Resource' in the properties grid

And try the same (again, from within 'MyLibrary')...

var imageSourceConverter = new ImageSourceConverter();
var packUriString = $"pack://application:,,,/Resources/Images/SomeFile.jpg";
someImage.Source = imageSourceConverter.ConvertFromString(packUriString) as ImageSource;

But I now get the following...

System.IO.IOException
  HResult=0x80131620
  Message=Cannot locate resource 'resources/images/somefile.jpg'.
  Source=PresentationFramework
  StackTrace:
   at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)

I remember issues with resources in the past not being compiled so I did a 'rebuild all' to see if that helped, but it didn't. Still get the same issue.

Any ideas?

c#
wpf
resources
asked on Stack Overflow Dec 8, 2020 by Mark A. Donohoe • edited Dec 8, 2020 by Mark A. Donohoe

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0