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:

enter image description here

with exception detail

enter image description here

i able track problem location in initializecomponent() method of view.xaml:

enter image description here

and more specificially within initializecomponent():

enter image description here

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:

  1. create usercontrol library usercontrol (usercontrol1)
  2. compile , copy dll (signed dll)
  3. change version , user control (textblock says "version 2" instead of "version 1")
  4. compile , copy dll (signed dll)

i then:

  1. fired telerik's justdecompile reflexil plugin (you can justdecompile's plugins manager).
  2. loaded dlls
  3. found uri's in initializecomponent methods
  4. modified uri's include version matches dll
  5. 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -