Welcome to irritatedVowel.com Sign in | Help

POKE 53280,0: Pete Brown's Blog

Silverlight, WPF, Woodworking, .NET Programming, CNC, Nature, and other topics.

Pete Brown writes on a number of topics including Silverlight, WPF, .NET, woodworking and working as a consultant in the DC area. On most forums, Pete goes by the name Psychlist1972. Pete has worked at Applied Information Sciences (AIS) since 1996 where he currently performs as a lead architect and project manager.

Subscribe to my feed

Add to Technorati Favorites
Applied Information Sciences - My Employer

Community Events



World Domination

who's online

Networks


View Pete Brown's profile on LinkedIn

AddThis Social Bookmark Button

How Silverlight is Loaded and Instantiated

At the end of the day on Saturday's Silverlight Dev Camp, I gave an ad-hoc talk on controls and silverlight. The conversation quickly turned to a lot of Q&A on how the Silverlight control and content is loaded. I covered that there, but for those who didn't attend, this is useful information.

When file requests are made to the server, they currently follow normal browser caching and access rules. Silverlight makes the request through the browser stack. Currently the DLLs are set to expire 29 hours from the request. As with any browser-based application, caching can get you in trouble when you are doing a lot of debugging. During my own tests here, I kept switching page.xaml back and forth between a version with the x:Class removed and one with it intact. I had to clear the browser cache in between changes in order to get back reliable results. Also note that if your files (including DLLs) on the server have not been changed and they care cached locally, you'll get back a 304 not-modified and the file will not be brought back down to the browser.

One key point that I spoke about and my testing proved out is that the only thing that decides whether or not your application is a CLR application or a JavaScript application, is the inclusion of x:Class in your main xaml file. The version number you put in createSilverlight is there only to check to make sure the user has a minimum version and redirect them to the correct download location otherwise. For example, I put "1.0" in the version parameter, and ran my Managed Silverlight application just fine because I had 1.1 already installed. This points to the fact that you will always need to test your Silverlight apps on a virgin machine to make sure that all the moving pieces are correctly configured. Just because it works on a machine that already has Silverlight installed does not imply that it works correctly on one without.

(The other thing this points to is a problem in public naming for Silverlight. Rather than 1.0 and 1.1 we should refer to them as Unmanaged and Managed Silverlight, or something along those lines, especially since 1.1 is backwards compatible with unmanaged Silverlight code "1.0".)

The DLLs are downloaded once your main xaml file is loaded (not in the "loaded event sense" but in the "file is loaded into memory" sense) and parsed. Silverlight decides on what DLLs to download by using the x:Class and the manifest in the DLLs, following normal .NET rules.

When attempting to resolve DLL locations, Silverlight will first check in the location of the main DLL (typically ClientBin) and then it will check in the location of the Page.xaml file (typically one level up). When downloaded, all these files end up in your temporary internet files folder. Clearing your cache in IE or FireFox is sufficient to remove the application from your local PC.

Each running instance of Silverlight, in the current 1.1 alpha, gets its own copy of the CLR and its own app domain. If you have five instances of Silverlight on your page, you get five CLRs. This isn't great for memory usage or performance, of course. I understand Microsoft is considering letting all instances within a browser app share an app domain in a future version. No public announcements have been made yet on that topic. In the mean time, try and keep your Managed Silverlight applications to one instance per page.

[ To test everything, I relied on Fiddler, Visual Studio 2008 Beta 2, and Silveright 1.1 alpha - September Refresh using IE7 and Windows XP SP2. In other configurations, your results may vary. Comments welcome. ]

  Add to Technorati Favorites
Posted: Wednesday, November 07, 2007 2:15 PM by Pete.Brown

Comments

Frank La Vigne said:

# November 7, 2007 6:45 PM

Frank La Vigne said:

# November 7, 2007 6:48 PM

Christopher Steen said:

Link Listing - November 7, 2007
# November 8, 2007 1:20 AM

Christopher Steen said:

ASP.NET BBCode extension for BlogEngine.NET 1.2 [Via: Mads Kristensen ] Dynamically Render A Web User...
# November 8, 2007 1:20 AM

WynApse said:

Silverlight Cream for November 8, 2007 -- #120
# November 8, 2007 3:20 PM

Catto said:

Hey Now Pete, Interesting Post. I like the summary: 'try and keep your Managed Silverlight applications to one instance per page.' Thx 4 the info, Catto
# November 9, 2007 10:31 AM

POKE 53280,0: Pete Brown's Blog said:

In a break from some of my previous Silverlight talks, today at the NoVA Code Camp, I did a mostly slideless
# November 17, 2007 6:22 PM

Rob Burke said:

This is a fantastic and very helpful summary. Thanks for doing the research and for posting this, Pete!
# November 25, 2007 3:53 PM

Ashish Shetty said:

You describe the flow pretty well. Silverlight relies on the browser stack for downloads and therefore cache control policies and user preferences etc. apply. There's no enforcement in our code of a 29hr wait. You final statements are not accurate though. There's one instance of CLR per host (browser) process, but you rightly state that there's 1 AppDomain per instance of Silverlight plug-in. The infrastucture overhead from multiple Silverlight instances on a page is fairly low. Are there specific perf issues you've encountered? The idea of sharing AppDomains among multiple SL instances on a page is interesting and indeed something we've dabbled with. I personally haven't seen scenarios that justify the cost and security risks. Are there great scenarios that you think would open up with that feature?
# November 29, 2007 7:21 PM

Pete.Brown said:

Hi Ashish

Thanks for the info and the correction on the instance issue.

The 1 CLR instance per app was based on that same comment and recommendation made by some MSFT folks at MIX and then (as I recall) on Silverlight.net. I'm glad to hear that there's only one CLR instance per Silverlight control. THe only perf issues I ran into were early on, and perhaps have been resolved. I had multiple silverlight controls on a page, running animations (like my balloons sample) and a simple button sample. CPU was getting pretty bogged at the time with even one Silverlight instance, so that test likely doesn't apply any more.

The main instance where I've been asked about multiple instances per page is when doing silverlight-based webparts in MOSS. Discrete silverlight-based menus and/or chrome and then any number of silverlight-based web parts that show, for example, video, charts, KPIs, etc. On a typical MOSS portal page, when Silverlight is used, you can probably expect to see 3-5 instances.

I also appreciate the validation of the flow. I got this just by testing the 1.1 alpha from the outside, so I'm glad I got some of it correct :)

Pete

# November 29, 2007 8:24 PM

Pete.Brown said:

I just realized that the yes/no labels didn't make it over from visio. odd. Anyway, if you look at the above, the branches off to the right are the "no" branches.

Pete

# November 29, 2007 10:52 PM

Poonam said:

I tried out a sample in Silverlight 1.1. It uses C# code behind for handling events. Code compiles just perfect in Orcas Beta2 studio. However, when I execute the code in IE 6.0, it does not show me any results :( I have silverlight 1.1 framework installed on my machine. However, I get a blank screen and Page_Load method never gets triggered. Could you please suggest what could be missing in this?
# December 8, 2007 6:24 AM

Pete.Brown said:

Hi Poonam Often times that means you have an error in your xaml itself. Strip the xaml down to just the very basics and see if you can get it to come up. XAML parsing errors can be tricky to catch. If that isn't it, please post your question on the silverlight.net "Programming with .NET" forum here: http://silverlight.net/forums/17.aspx I'll be able to better help you there. When you post, please post the important bits of code/xaml that you use. Pete
# December 10, 2007 8:31 AM

Ray akkanson said:

Are there any changes as far as loading and instantiating for silverlight 2.0? Ray Akkanson
# May 27, 2008 11:11 AM

Pete.Brown said:

@Ray yes, there are a number of changes. Please see my two-part article from March 2008 http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2008/03/05/Xap_2100_-App_2100_-Pow_2100_-Packaging-and-Application-Startup-in-Silverlight-2-Beta-1-_2D00_-Part-1.aspx Also, to answer the question you posted on my beta site regarding the chat app code, please see the two-part Silverlight Chat application article I posted this month. (You didn't leave an email address there and don't have one on your site) Hope that helps! Pete
# May 27, 2008 11:43 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Enter the text you see in the image:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS