Export (0) Print
Expand All

AssemblyPart.Load Method

Silverlight

Converts a Stream to an Assembly that is subsequently loaded into the current application domain.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

'Declaration
<SecuritySafeCriticalAttribute> _
Public Function Load ( _
	assemblyStream As Stream _
) As Assembly

Parameters

assemblyStream
Type: System.IO.Stream
The Stream to load into the current application domain.

Return Value

Type: System.Reflection.Assembly
The Assembly that is subsequently loaded into the current application domain.

You cannot load multiple versions of the same assembly into the current application domain.

The following code example demonstrates how to use this method to download a remote assembly and then load it into the application domain.


<UserControl x:Class="SilverlightApplication.HomePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Grid Background="SandyBrown">
        <StackPanel x:Name="stackPanel">
            <TextBlock>Page from Host Application</TextBlock>
            <TextBlock 
                MouseLeftButtonUp="TextBlock_MouseLeftButtonUp"
                Cursor="Hand">
                Click Here to Display a UI from the Library Assembly
            </TextBlock>
        </StackPanel>
    </Grid>


</UserControl>



Imports SilverlightLibrary

Partial Public Class HomePage
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub TextBlock_MouseLeftButtonUp(ByVal sender As Object, _
        ByVal e As MouseButtonEventArgs)

        ' Download an "on-demand" assembly. 
        Dim wc As New WebClient()
        AddHandler wc.OpenReadCompleted, AddressOf wc_OpenReadCompleted
        wc.OpenReadAsync(New Uri("SilverlightLibrary.dll", UriKind.Relative))

    End Sub

    Private Sub wc_OpenReadCompleted(ByVal sender As Object, _
        ByVal e As OpenReadCompletedEventArgs)

        If (e.[Error] Is Nothing) AndAlso (e.Cancelled = False) Then

            ' Convert the downloaded stream into an assembly that is 
            ' loaded into current AppDomain. 
            Dim assemblyPart As New AssemblyPart()
            assemblyPart.Load(e.Result)

            DisplayPageFromLibraryAssembly()

        End If

    End Sub

    Private Sub DisplayPageFromLibraryAssembly()

        ' Create an instance of the Page class in the library assembly. 
        Dim page As New Page()

        ' Display the new Page. 
        Me.stackPanel.Children.Add(page)

    End Sub

End Class


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft