views:

390

answers:

2

I have a ListBox that gets populated with items read from a JSON response. Each item has an Image control that displays the thumbnail at the remote URL given by the Thumbnail property. I created a custom IValueConverter to convert the URL to a BitmapImage, but the image still didn't display. So I finally realized that I could capture loading errors with the ImageFailed event.

What I get is an AG_E_NETWORK_ERROR. I looked at Silverlight's URL Access Restrictions and the table states that loading an Image from another domain is allowed without a crossdomain.xml file.

I'm positive that the URL is valid and points to an image, because I can copy and paste it directly from the JSON and view it in a browser. Yet, Silverlight refuses to load it.

Why is this?

EDIT: I installed Fiddler, which does show requests being made when the Silverlight page is loaded. None of these requests are for the image, however. It appears that Silverlight isn't even attempting to make a request and automatically throwing the exception.

+1  A: 

Are you actually trying to download the image (binary content) using WebClient or another HTTP stack in Silverlight? Unless you can write that cross domain file, this is not possible.

I believe you must just set the URL of the Image.Source, which then would let Silverlight resolve the image. You would also see Fiddler make the request at that time.

Jeff Wilcox
A: 

Someone answered this on the Silverlight forums. The problem turned out to be that I was using the auto-generated debug page, instead of an IIS website. Silverlight doesn't allow cross-protocol calls (in this case, from file:// to http://).

David Brown