c# - Loading and unloading WPF assembly from arbitrary path -


i'm struggling find way load , unload wpf assembly arbitrary path (not sub directory of base path) c# console application.

i'm exploring stackoverflow couple of days (as have done other forums), can't find way how console application loading wpf assembly , instantiating object assembly.

starting point following example c# console application:

using wpflibrary;  namespace caller {     class program     {         [stathread]         static void main(string[] args)         {             samplewindow wnd = new samplewindow();             wnd.showdialog();         }      }  } 

and following code wpf assembly:

namespace wpflibrary {        public partial class samplewindow : window     {                public samplewindow()         {             initializecomponent();         }    } } 

i found various similar questions , suggestions use:

  • reflection via: assembly.load();
  • using activator.createinstance();
  • using different appdomain createinstanceandunwrap
  • using assemblyresolve appdomain etc.
  • etc

but never simple example above working if wpflibrary not in sub directory of base path of caller console application. since i'm new in field may have missed simple thing or scenario may impossible.... appreciated.

background of question:

in case not interested understand motivation question skip remaining of post. developing c++ dll application commercial cad system. interface system c/c++ there no way change complete code c# application. application includes simple scripting language allows define , execute graphical user interface. encoded in win32 / mfc way, since includes self build layout manager idea think other alternatives. perfect match seems use use wpf, requires use .net , allow xaml definitions c# library connected c++/cli dll seems setup.

some major requirements are:

  • the wpf dll must able load installation of application.
  • it required stop , restart application (so wpf assembly needs removed , reloaded).

i had kind of similar, although console app starting wpf app. maybe help:

    static void main(string[] args)     {         initialise();         if (!runsilently)             fireupgui();         else             runconsoleapp();   // not relevant answer     }     private static void fireupgui()     {         console.setwindowsize(80, 5);         thread t = new thread(start_wpf);         t.setapartmentstate(apartmentstate.sta);         t.start();     }     static app wpfapp;     static void start_wpf()     {         wpfapp = new app();   // wpf app         wpfapp.run();     } 

it's worth noting though app class in same assembly console app, meant referenced normal wpf framework assemblies.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -