How to load assembly into memory and execute it

前端 未结 3 894
暗喜
暗喜 2021-01-01 00:52

This is what im doing:

byte[] bytes = File.ReadAllBytes(@Application.StartupPath+\"/UpdateMainProgaramApp.exe\");
Assembly assembly = Assembly.Load(bytes);
/         


        
相关标签:
3条回答
  • 2021-01-01 01:30

    if you check any WinForm application Program.cs file you'll see there always these 2 lines

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    

    you need to call as well them in your assembly. At least this is what your exception says.

    0 讨论(0)
  • 2021-01-01 01:41

    How about calling it in it's own process?

    0 讨论(0)
  • 2021-01-01 01:51

    The entry point method is static, so it should be invoked using a null value for the "instance" parameter. Try replacing everything after your Assembly.Load line with the following:

    assembly.EntryPoint.Invoke(null, new object[0]);
    

    If the entry point method is not public, you should use the Invoke overload that allows you to specify BindingFlags.

    0 讨论(0)
提交回复
热议问题