I tried to load assembly dynamically from a xap file like below:
AssemblyPart asmPart = new AssemblyPart();
StreamResourceInfo streamInfo = Application.GetResourceStream(new StreamResourceInfo(xapFileStream, "application/binary"), new Uri(source, UriKind.Relative));
Assembly asm = asmPart.Load(streamInfo.Stream);
FrameworkElement element = asm.CreateInstance(className) as FrameworkElement;
Then I tried to load the user control MainPage. If MainPage is simple as:
If the
namespace TestApp
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
}
}
It's fine. But if the MainPage like:
namespace TestApp
{
public partial class MainPage : UserControl
{
private readonly Dictionary<IWorkbenchWidget, TabControlElement> tabs;
public MainPage()
{
InitializeComponent();
base.Loaded += new RoutedEventHandler(myHandler);
}
}
}
It failed.
So want to know if use Assembly.CreateInstance to create a instance of a class, any special request on the class?