I want to create multiple instances of a .xaml UserControl named view.xaml
, which resides in an assembly dir1\asm.dll
and dir2\asm.dll
whereas asm.dll
is the same assembly that only differs in its version number and the implementation of view.xaml.
I have the following setup:
public void TestCreation() {
Assembly asm = null;
asm = Assembly.LoadFile("dir1\asm.dll");
CreateView(asm); // works!
asm = Assembly.LoadFile("dir2\asm.dll");
CreateView(asm); // works!
asm = Assembly.LoadFile("dir1\asm.dll");
CreateView(asm); // FAILS!
}
public void CreateView(Assembly assembly)
{
Type type = assembly.GetTypes().First<Type>(t => t.Name.Equals("View"));
UserControl view = (UserControl)assembly.CreateInstance(type.FullName, false, BindingFlags.CreateInstance, null, new object[] { }, null, null);
}
I am getting the following Exception:
with the Exception detail
I was able to track the problem up to this location in the InitializeComponent() method of my view.xaml:
and more specificially within InitializeComponent():