c# - Creating multiple .xaml Views -
i want create multiple instances of .xaml usercontrol named view.xaml
, resides in assembly dir1\asm.dll
, dir2\asm.dll
whereas asm.dll
same assembly differs in version number , implementation of view.xaml.
i have 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 getting following exception:
with exception detail
i able track problem location in initializecomponent() method of view.xaml:
and more specificially within initializecomponent():
well, kind of fun...
both assemblies have same resource uri. work if uri contained version vs doesn't seem put in there. ever 1 loaded last (asm1 or asm2) seems able use non-versioned uri without crashing.
if, instead of: "/problemeditor;component/problemeditor.xaml"
you had: "/problemeditor;v1.0.0.0;component/problemeditor.xaml" , "/problemeditor;v2.0.0.0;component/problemeditor.xaml"
then there wouldn't problem.
what did recreate environment was:
- create usercontrol library usercontrol (usercontrol1)
- compile , copy dll (signed dll)
- change version , user control (textblock says "version 2" instead of "version 1")
- compile , copy dll (signed dll)
i then:
- fired telerik's justdecompile reflexil plugin (you can justdecompile's plugins manager).
- loaded dlls
- found uri's in initializecomponent methods
- modified uri's include version matches dll
- did "save as" on dlls. since signed , modified them, reflexil delay signed offered remove strong name or re-sign key (you have provide .snk key file, of course). re-signed them since have key file.
then code above works! works! works!
i hope acceptable solution you. if else has way around without hacking dlls, i'd interested know well.
Comments
Post a Comment