Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application.GetResourceStream called on a Content Resource still return null

Here is the task-related part of the VS2010 project (Windows Phone) structure:

enter image description here

The code is being executed from DummyMediaLibProvider.cs:

public class DummyMediaLibProvider: IMediaLibProvider
{
    ...
    StreamResourceInfo albumArtPlaceholder = 
        Application.GetResourceStream(
            new Uri("../Images/artwork.placeholder.png", UriKind.Relative));

artwork.placeholder.png Build Action is set to Content.

Still, whenever I run the code, Application.GetResourceStream returns null.

What may be the reason for the resource not being read to memory?

I have attempted to delete obj directory of the project, did Clean and Rebuild, but so far nothing helped.

Update:

If I apply Build Action: Resource to artwork.placeholder.png, I can get the resource stream ok though.

P.S. This is not the duplicate of Application.GetContentStream returns null for content Uri since the last had the extension (particurarly .xml) related problem.

like image 583
Maxim V. Pavlov Avatar asked Sep 12 '11 21:09

Maxim V. Pavlov


1 Answers

The path supplied Application.GetResourceStream isn't relative to the position of the class, but relative to the application package.

StreamResourceInfo albumArtPlaceholder = 
    Application.GetResourceStream(
        new Uri("Images/artwork.placeholder.png", UriKind.Relative));

Would be the correct path. You can also try with a full pack URI. (see MSDN)

And finally, Resource would be the correct Build Action for this.

like image 161
Claus Jørgensen Avatar answered Oct 20 '22 15:10

Claus Jørgensen