How does silverlight work in web browser? - silverlight

How does Silverlight application work in browser?
E.g When I access a page having Silverlight control, how does Silverlight runtime extract data/ dlls from 'XAP' package? does it load all dlls in one go or support lazy loading of dlls?

If you're interested in some of the inner working of how the silverlight plugin and how it reads the XAP visit http://stuff.seans.com/2009/03/23/hello-silverlight-world-part-3-the-lifecycle-of-a-silverlight-control/#comment-826
He sums it up very well.

The Silverlight Runtime will extract and load all the DLLs from the Xap file before executing the entry point. Other files within the Xap will be extracted in an on demand fashion.
If you have significant "data" files in your Silverlight project and they need to be in the Xap add them as "Content" rather than as "Resource".
For larger Silverlight apps there are technologies such as MEF which allow you to divide up your app into multiple XAPs and support the dynamic loading of dlls.

Silverlight xap file is just a zip file that contains all required dll s, and files for executing. browser downloads, than extracts files and start executing using Silverlight player, which is light version of .NET engine. Of course there are technologies for lazy loading dll's too, I guess, if you need it.

Related

Silverlight on-demand compilation/Build

Is it possible to build silverlight application in on-demand manner. I have lot of silverlight applications to be shipped. I would like to ship the project files alone. Based on some user interaction, I would like to generate the XAP.
You thought about using a NANT script to compile your project and grab the output xap file?

Is it possible to have REF to a Silverlight class library (dll) module in ModuleCatalog.xaml

I am working with Silverlight 4.0 and Windows Application Composite Framework (Prism).
I have created couple of modules which are Silverlight libraries so they are compiled into dlls and not xaps.
I want to register these modules into my Shell application using ModuleCatalog.xaml. If I package my modules into .xap then this approach works fine but since my modules are .dll, I am getting exception during load.
So my question is, will be possible to register silverlight module dll in ModuleCatalog.xaml?
This is not possible because Silverlight packages assemblies in .xap packages. Thus, if an assembly is not in the main .xap (the one of the Shell), Prism must know how to download the .xap file where it's located at to be able to download and load modules correctly.
Imagine that, if the application downloaded the module's from a server, downloading the .xap package and loading an assembly in the application is possible and easy in Silverlight, while doing it directly with a .dll is not.

large silverlight site (hundreds of pages)

When you surf a silverlight site, I believe it downloads the site to the client.
Excluding practicality, lets say your going to develop a large full silverlight site with nearly a thousand pages of static content.
Is there any way you can set the compiler to divide the silverlight app in small parts that will only download as a user attempts to access different areas of the huge site?
You need to use Managed Extensibility Framework (MEF) of Silverlight.
With it you can create small silverlight projects and load them when you need.
Here are some links:
3 Steps to MEF - Export, Import, Compose from silverlight.tv
When and Where to use MEF from silverlight.tv
Using MEF with Silverlight 4 for Extensibility from silverlight.net
To be more specific it downloads the XAP file to the client, which is the end product for your silverlight project.
(Input) Silverlight project -> (Output) one XAP File (containing the main assembly and its dependencies) compressed in a normal ZIP file, but ironically renamed to take XAP extension.
Yes, this is doable, see my answer HERE, you need the same methodology depending on the control (portion) you need upon a specified condition.

Dynamically loading Silverlight XAPs

I have four Silverlight 4 apps, each in their own Visual Studio project, for which I want to write a "shell" to host them so they appear to the user as a single application. To minimize download times, I will download the XAPs and supporting DLLs dynamically. So I will end up with 5 apps - the shell and the four sub-apps. Now my problem:
My apps all reference the Telerik suite, and this is a fairly significant download. When I build my apps, the Telerik DLLs get zipped into each XAP (as expected). So even if I dynamically load the XAPs, the Telerik DLLs will be downloaded multiple times, once for each XAP.
So how do I make it so the Telerik DLLs are downloaded only once (say, by the Shell), and shared by all the sub-applications?
If you go into the Properties window of your various Silverlight projects, and select the "Silverlight" tab, you'll see an option to "Reduce XAP size by using application library caching". If you select that, the support libraries (Telerik, in this case) will get packaged into separate .zip files that can be downloaded separately. See here for more details, including instructions on how to configure your own assemblies for this sort of behavior. (I presume, though I haven't checked, that Telerik has done this with their controls.)

Xap file contents changes if built in Visual Studio or build server

I'm using MEF with my Silverlight 4 app to dynamically load xap files. To optimize this process, I've removed various assemblies from my xaps since I know they've already been loaded by the base xap. This reduces the size of my dynamically loaded xaps. I accomplished this by setting the "Copy Local" flag for each assembly reference to "false".
This all seems to work fine when I build in Visual Studio 2010 - my xaps are much smaller. However, when the same projects are built by the build server, all the excluded references are once again in the xap file hence tripling the size of the xap.
I've read several blogs/articles regarding similar experiences but no resolution. Very frustrating - any help is appreciated.
Xap files are just Zip files with a different extension. So if you can't figure out why the build server is including the assemblies you don't need, you could create a post-build step that treats the Xap as a Zip and removes those assemblies from it.

Resources