vendredi 14 avril 2017

C# - How to use reflection run in memory with a winform

Im using this code to run my file

        byte[] test = File.ReadAllBytes("TestFile.exe");
        Assembly a = Assembly.Load(test);
        MethodInfo m = a.EntryPoint;
        var parameters = m.GetParameters().Length == 0 ? null : new[] { new string[0] };
        m.Invoke(null, parameters);

If I do this in a console application it works like charm. I can execute other managed console windows or winforms. But when I enter this code in a windows form to execute another file in memory. I always get the following error:

System.InvalidOperationException

Parameter count mismatch





Aucun commentaire:

Enregistrer un commentaire