Digital Transfusion

Putting the internet in your veins!

Silverlight Splash Screen Source fails to load my XAP

1 comment

It sounds like a pretty bold statement, but it is true. There is a way to break the built in Silverlight 4 splash screen loader. Most people will probably never see the problem. I only found this bug because the website I am building uses an Akamai caching network that was mis-configured. It was an honest mistake because not everyone is used to using the .xaml mime type yet. IIS 7 works correctly out of the box and shouldn’t have this problem. Anyway, here is what is going on.

The setup

Just to make sure everyone is on the same page, here is the setup I will be using. All names have been changed to protect the innocent.

TestApp.html: (this is the page that will host the .xap)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Page Title</title>
        <script type="text/javascript">
            function onSourceDownloadProgressChanged(sender, eventArgs) {
            sender.findName("progressText").Text = eventArgs.progress;
            }
        </script>
    </head>
    <body>
        <div id="silverlightControlHost">
            <object data="data:application/x-silverlight-2,"
                    type="application/x-silverlight-2"
                    width="100%" height="100%">
            <param name="source" value="/ClientBin/MyApplication.xap" />
            <param name="splashScreenSource" value="/SplashLoader.xaml" />
            <param name="onSourceDownloadProgressChanged"
                   value="onSourceDownloadProgressChanged" />
            <param name="initParams" value="param=data" />
            <param name="background" value="black" />
            <param name="minRuntimeVersion" value="3.0.40818.0" />
            <param name="autoUpgrade" value="false" />
            </object>
        </div>
    </body>
</html>

SplashLoader.xaml: this is the loose xaml page that will be loaded as the splash screen

<Grid
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="parentCanvas"
    Width="Auto"
    Height="Auto">
    <Grid Background="Black">
        <Grid HorizontalAlignment="Center"
              VerticalAlignment="Center"
              RenderTransformOrigin="0.5,0.5">
            <TextBlock x:Name="progressText"></TextBlock>
        </Grid>
    </Grid>
</Grid>

What is going on?

if you look at the following picture:

image

In the first pass through (fiddler capture 1), you will see that the application loads both the .xap and the splashloader.xaml. (200 response) Neither are cached. The application loads just fine because the .xaml page has a chance to download an instantiate while the .xap file is still being downloaded. The progress bar updates correctly, and the world is happy.

Where this process breaks down is if you don’t have .xaml files allowed to be cached, but the .xap files are. (fiddler capture 2) You can see that the .xap file is already downloaded and trying to instantiate while the .xaml file still needs time to download. Because the .xap is already loaded and ready to go, there isn’t ever a “download progress” tick, so the splash screen hangs at that point.

To prove that it works with caching, you can use Fiddler’s  AutoRespond (or something like it) to reply back with a code 304. the file is loaded locally, and it begins to load again.

image

In summary

Like I said at the beginning of this article, IIS7 works correctly out of the box. If you find yourself in this situation, check your settings, and make sure that the.xaml pages can return a 304. I honestly don’t know if you can even break this in IIS7, but for people using other caching networks, web accelerators, etc…it is entirely possible to miss this setting.

It took me a lot of troubleshooting to figure this one out, so I hope this post helps someone out there save a few hours of mind numbing debugging. We can only hope that this is fixed in SL5.

IIS7 stops responding without an error

no comment

One of the most maddening things in the world is when you have a problem with your application, but there isn’t an error code. Well recently I had such an error, and I hope I can save a few people from ripping out their hair.

IIS7 appears to work correctly, but after loading a single page it just stops responding to anything. No errors are given, the website just times out. Sometimes it would load half of the page before it would fail, so you would get to see what your page looked like without CSS. Not even raw images come up in a timely fashion.

If these symptoms sound remotely close to what you were seeing you have probably looked around the net and seen the threads about a problems with IIS7 and FF. The fix was to increase the timeout of worker threads. I have a hard time believing that increasing a timeout value is at all beneficial. (websites are supposed to load quickly right?)  Besides, I was using IE so it didn’t make sense.

It turned out to be AVG.

I am not sure if a new tweak to the resident shield is to blame, or something else, but having AVG installed on my machine causes IIS7 to lock up on heavy sites. Disabling AVG didn’t help. I had to completely remove it for the website to work.

I hope they figure out what the problem is and fix it soon, but in the meantime I will have to make do without AVG.