在SIlverlight中加载远程映像时的AG_E_NETWORK_ERROR [英] AG_E_NETWORK_ERROR when loading a remote Image in SIlverlight
问题描述
我有一个 ListBox
,它填充从JSON响应读取的项目。每个项目都有一个 Image
控件,显示由缩略图
属性指定的远程URL的缩略图。我创建了一个自定义 IValueConverter
将URL转换为 BitmapImage
,但是图像仍然没有显示。所以我终于意识到我可以捕获加载错误与 ImageFailed
事件。
我得到的是一个 AG_E_NETWORK_ERROR 。我查看了Silverlight的网址访问限制和表格中指出,如果没有 crossdomain.xml 文件,则允许从其他域加载图片
。
我认为网址有效并指向图片,因为我可以直接从JSON复制并粘贴它,并在浏览器中查看。
编辑:
>我安装了Fiddler,它显示在加载Silverlight页面时发出的请求。然而,这些请求都不是针对映像的。看来,Silverlight甚至没有尝试发出请求并自动抛出异常。有人在Silverlight上回答了这个问题论坛。问题原来是,我使用自动生成的调试页面,而不是IIS网站。 Silverlight不允许跨协议调用(在这种情况下,从file://到http://)。
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.
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://).
这篇关于在SIlverlight中加载远程映像时的AG_E_NETWORK_ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!