Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7952715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:56:33+00:00 2026-06-04T02:56:33+00:00

I am creating a program to see if I can run a byte array

  • 0

I am creating a program to see if I can run a byte array in C#.

The program should grab a byte array “MyBinaryData” and Load+Run it as a new program.
There will be a text box where you can enter the bytes to see the outcome (it’s a experiment 😉 ).
I have tried this:

 byte[] binaryData = System.IO.File.ReadAllBytes("MyBytes.txt");  // the bytes are in a .txt file for simple tests before becoming a textbox.
 Assembly LoadByte = Assembly.Load(binaryData);
        MethodInfo M = LoadByte.EntryPoint;

        if (M != null)
        {                object o = LoadByte.CreateInstance(M.Name);
            M.Invoke(o, new Object[] { null });  // this gives the error
        } 
        else {  
         ..... fail code here.... 
             } 

The problem is that it gives this error:
“System.Reflection.TargetInvocationException:……SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.”

My second test was:

 Assembly assembly = Assembly.Load(binaryData);

 Type bytesExe = assembly.GetType(); // problem: the GetType(); needs to know what class to run.
 Object inst = Activator.CreateInstance(bytesExe);

But this needs to know what class in the byte array it needs to run.

I then tried:

var bytes = Assembly.Load(binaryData);
var entryPoint = bytes.EntryPoint;
var commandArgs = new string[0];
var returnValue = entryPoint.Invoke(null, new object[] { commandArgs });

But it gave me this:
“System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.InvalidOperationException: SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.”

My program.cs is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Crypter
{
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form2());
    }
}

}

What other way can I do this to have the Whole program opened?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:56:35+00:00Added an answer on June 4, 2026 at 2:56 am

    You have two way

    first way make .exe from that byte array and then start it

    second look at this execute byte array

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Load local HTML file in a C# WebBrowser I´m creating program in
im creating a program that will compile java files, at the moment i have
Situation Well, as you can see below, I have a main App, creating a
I am creating a program that is effectively an sprite creator. I'm very new
dg.ItemsSource=GetList(); I debug the program and see that ItemSource receives full items but there
I'm creating a program that invents a new Sudoku puzzle. The way I initially
I creating a program which send newsletter with a background image. It works fine
I am creating a program that calculates rainfall for the year etc. I had
I'm creating a program in VB.net that does the following: At a high level
I am creating a program where the user creates custom commands and execute them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.