Posts Tagged ‘Reflection’
24
Sep

Loading external assembly

Post a comment » Popularity: 1%

Terence Tsang demonstrated how to load an external assembly library (Usually a dll or xap file) into your own Silverlight application. This is a very effective method to minimize the application file size.

Loading external assembly

Loading external library in C#:
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(onDownloadCompleted);
downloader.OpenReadAsync(new Uri(DLL_PATH, UriKind.Absolute));  

// Once the assembly is downloaded
private void onDownloadCompleted(object o, OpenReadCompletedEventArgs args)
{
    try
    {
        AssemblyPart ap = new AssemblyPart();
        Assembly assembly = ap.Load(args.Result);
        Object control = assembly.CreateInstance(CLASS_NAME);
    }
    catch (Exception e){}
}