Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

c# - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...