AG_E_NETWORK_ERROR when loading a remote Image in SIlverlight

佐手、 提交于 2020-01-13 06:42:49

问题


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:


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://).




回答2:


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.




回答3:


Another way:

  1. Add de Web project in order to have your own development server.
  2. Set it as startup project.
  3. Open its properties. Web tab: mark specific page.
  4. Web tab / Debuggers (at the bottom): mark Silverlight.

Now you can run & debug your Silverlight application without installing an ISS Server.



来源:https://stackoverflow.com/questions/1793487/ag-e-network-error-when-loading-a-remote-image-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!