views:

44

answers:

1

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?

A: 

The problem appears to be with:

base.Loaded += new RoutedEventHandler(myHandler);

You do not have an event handler named "myHandler" defined in MainPage (unless you omitted it for brevity?).

KeithMahoney

related questions