views:

45

answers:

1

I'm sure that this is a simple newbie question, but the answer is eluding me right now.

I have the following control compiled in Silverlight 3:

<UserControl x:Class="SLImageTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <StackPanel>
        <Image Source="http://farm3.static.flickr.com/2733/4102919659_0207842bde_m.jpg" />
    </StackPanel>
</UserControl>

The image source isn't important, but you can verify that

When I run the control, I don't get an image shown. So something is set up wrong despite my efforts. What has gone wrong?

But there is no debug output as there should be on a binding error, no exception thrown, no indication given of anything at all failing! Why is that?

Code much like this works fine in WPF.

If I include the image into the project, and do

<Image Source="kitten1.jpg" />

That works fine. But it's not what I want.

+2  A: 

My guess is that you're running it from a file:// URL and not an http:// URL. Look at the URL in the browser address bar to determine if this is true. That is a cross protocol access issue. The simple solution is to try it from the built-it web server in Visual Studio or Expression Blend. Debug your application from Visual Studio or run it from Blend and you'll see it has an http://localhost URL.

Michael S. Scherotter
The image URL is as given, a http: url. The Silverlight control was run from a file:///C:/ url.I tried a new project using a web page to host the Silverlight control to put it on a http://localhost: url and it works fine now. So why does this make a difference, and where is the error info going?
Anthony
It does make a difference - as a cross-protocol access violation. file:// cannot access http:// and http:// cannot access file:// Silverlight is meant to be run from the web so if the app were to be posted to a web server, it would work as expected.The easy thing to do is to test it from IIS running on your system or from the web server that comes with Blend and Visual Studio.
Michael S. Scherotter
This seems to be correct. Why no debug or error info though? It's pretty poor not to provide any.
Anthony
Flash has the same security model. The basic argument being that you don't want a file with full local permissions, being able to then tell the internet anything at all. (e.g. hacker writes code to scan your documents directory, and upload everything it finds to the internet). This is one of the many reasons I do all my development with a local webserver, and virtual hosts.
merlinc