c# SetCompatibleTextRenderingDefault must be called before the first -


i tried search exception couldn't find solution on case

i'am using code below invoke .net application :

        assembly assem = assembly.load(data);         methodinfo method = assem.entrypoint;                    var o = activator.createinstance(method.declaringtype);                     method.invoke(o, null); 

the application invoked has form , in entrypoint of application :

    [stathread]     static void main()     {         application.enablevisualstyles();         application.setcompatibletextrenderingdefault(false); //exception         application.run(new form1());     } 

setcompatibletextrenderingdefault must called before first iwin32window object created in application.

edit :

        assembly = assembly.load(data);         methodinfo method = a.gettype().getmethod("start");         var o = activator.createinstance(method.declaringtype);                     method.invoke(o, null); 

you should create new method skips initialization.

[stathread] static void main() {     application.enablevisualstyles();     application.setcompatibletextrenderingdefault(false); //exception     run(); }  public static void run() {     application.run(new form1()); } 

and reflection run method. application.run block current thread. if don't want start new message-pump, should try lookup form class reflection.


update:

class program {     static void main(string[] args)     {         var path = path.getdirectoryname(assembly.getentryassembly().location);         var filename = path.combine(path, "windowsformsapplication1.exe");         var assembly = assembly.loadfile(filename);         var programtype = assembly.gettypes().firstordefault(c => c.name == "program"); // <-- if don't know full namespace , when unique.         var method = programtype.getmethod("start", bindingflags.public | bindingflags.static);         method.invoke(null, new object[] { });     } } 

and loading assembly:

static class program {     /// <summary>     /// main entry point application.     /// </summary>     [stathread]     static void main()     {         application.enablevisualstyles();         application.setcompatibletextrenderingdefault(false);         start();     }       public static void start()   // <-- must marked public!     {         messagebox.show("start");         application.run(new form1());     } } 

this works here!


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -