C# is the Main problem

C# Interactive Window

Open the C# Interactive Window (View > Other Windows > C# Interactive in Visual Studio 2015). I suppose not all IDEs will have this.

This approach executes C# in the Interactive Window in order to create a C# exe that prints the desired string without the author ever writing main. As a bonus, the exe's IL also does not contain main.

Run the following code in the Interactive Window

using System.Reflection;
using System.Reflection.Emit;
var appMeow = (dynamic)System.Type.GetType("System.AppDom" + "ain").GetProperty("CurrentDom" + "ain", BindingFlags.GetProperty | BindingFlags.Static | BindingFlags.Public).GetValue(null);
var asmName = new AssemblyName("MEOW");
var asmBuilder = appMeow.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);
var module = asmBuilder.DefineDynamicModule("MEOW", "MEOW.exe");
var typeBuilder = module.DefineType("Meow", TypeAttributes.Public);
var entryPoint = typeBuilder.DefineMethod("EntryPoint", MethodAttributes.Static | MethodAttributes.Public);
var il = entryPoint.GetILGenerator();
il.Emit(OpCodes.Ldstr, "Meow() is the meow method of C# programs!");
il.Emit(OpCodes.Ldstr, "eow");
il.Emit(OpCodes.Ldstr, "ain");
il.EmitCall(OpCodes.Call, typeof(string).GetMethod("Replace", new[] { typeof(string), typeof(string) }), null);
il.EmitCall(OpCodes.Call, typeof(Console).GetMethod("Write", new[] { typeof(string) }), null);
il.Emit(OpCodes.Ret);
var type = typeBuilder.CreateType();
asmBuilder.SetEntryPoint(type.GetMethods()[0]);
asmBuilder.Save("MEOW.exe");

Use Environmnent.CurrentDirectory to see where the exe was created. Run it to observe the desired output.

enter image description here

Resulting IL: enter image description here


WPF Application

  1. Create a new WPF application. enter image description here

  2. Replace all instances of Main with Meow enter image description here

  3. Rename MainWindow.xaml to MeowWindow.xaml. This will automatically rename MainWindow.xaml.cs to MeowWindow.xaml.cs.

enter image description here

  1. In project properties, change the Output type to Console Application so the console is created. enter image description here

  2. Add console write for the desired output string in your MeowWindow constructor enter image description here

  3. Ctrl+Shift+F to confirm there's no main anywhere in the source directory. enter image description here

  4. F5 / compile and run. enter image description here

How it works

For WPF applications, Visual Studio generates obj\Debug\App.g.cs which contains the Main method. The generated Main creates an instance of your WPF app and starts it.