Blundering through Silverlight - images

Early in the Silverlight 4 in Action book, there is an example to work through; Creating a Twitter client with Silverlight. Just the fact that the author can use this as a "hello world" style example gives the reader a little indication of how powerful Silverlight is for building web apps. However, somewhere along the way I managed to mess things up in just this simple example. Which brings us to sticking point number two:

"I can't see any images"

One of the many handy controls in the Silverlight developer's toolbox is the Image. To get an image from an internet location, you just set the Source property to the right URI, and the rest works like magic. Only in my case, it didn't. Even stranger than that... I could "hard code" a URI in XAML and see the image in the designer, but there were no images in the running application!
Let's cut straight to the ending... I hadn't quite followed all the steps. At some point I'd changed the project from running in an ASP.NET server to just running from a file (probably while trying to get the debugger to work). Now, if you read the documentation on the Image.Source property closely, you'll see this paragraph:
"Cross-domain URIs are permitted, and specifying the scheme is permitted, but mixing URI schemes (such as accessing an HTTPS image from a Silverlight plug-in hosted on an HTTP-served HTML page) is not permitted"
In this case, an application running at a file:// location can't access images from an http:// location. Switch back to running using ASP.NET, and everything is fine.
comments powered by Disqus