{"record":{"id":"5ce2f728d77cccbb","repo":"dotnet/wpf","slug":"error-type-0-has-no-main-method","errorCode":null,"errorMessage":"Error: Type '{0}' has no Main method","messagePattern":"Error: Type '(.+?)' has no Main method","errorType":"exception","errorClass":"CspProjectException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WpfGfx/tools/csp/Project.cs","lineNumber":200,"sourceCode":"            )\n        {\n            if (sMainClass == null)\n            {\n                sMainClass = FindMainClass();\n            }\n\n            Object returnValue = null;\n\n            Type tMainClass = _assembly.GetType(sMainClass);\n            if (tMainClass == null)\n            {\n                throw new CspProjectException(\n                    \"Error: Project does not contain type '\" + sMainClass +\"'\");\n            }\n\n            if (!IsMainPresent(tMainClass))\n            {\n                throw new CspProjectException(\n                    \"Error: Type '\" + sMainClass +\"' has no Main method\");\n            }\n            \n            try\n            {\n                if (_breakBeforeInvoke)\n                {\n                    // This breakpoint is just before we execute the project we've compiled.\n                    // If you want to debug the project, step into the following \"InvokeMember\"\n                    // call.\n\n                    System.Diagnostics.Debugger.Break();\n                }\n\n                returnValue = \n                tMainClass.InvokeMember(\n                    \"Main\",\n                    BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static,","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WpfGfx/tools/csp/Project.cs#L182-L218","documentation":"Project.ExecuteMain in the csp tool throws CspProjectException when the resolved main class type does not contain a Main method (IsMainPresent returns false). The csp tool invokes the class's Main as the project's entry point, so a class without a valid Main makes execution impossible.","triggerScenarios":"The type declared as the project's main class exists in the assembly but defines no static Main method (with a signature csp recognizes), e.g. entry point renamed, made non-static, or given an unsupported parameter list.","commonSituations":"Refactoring Main into another method name; converting Main to async Main or adding parameters the tool does not accept; pointing the project at a class that is a library type rather than an entry-point class.","solutions":["Add a valid entry point to the class: `static void Main(string[] args)` (or the exact signature csp expects).","Point the project's mainClass setting at a class that already has a Main method.","Restore the original Main signature if it was changed to an unsupported form."],"exampleFix":"// before\nclass Runner { public void Start() { ... } }\n// after\nclass Runner\n{\n    public static void Main(string[] args) { ... }\n}","handlingStrategy":"validation","validationCode":"var mainType = asm.GetType(sMainClass);\nvar hasMain = mainType?.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)\n    .Any(m => m.Name == \"Main\") ?? false;\nif (!hasMain) throw new Exception($\"{sMainClass} has no Main method\");","typeGuard":"static bool HasMain(Type t) => t?.GetMethod(\"Main\", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null;","tryCatchPattern":"try { project.ExecuteMain(); }\ncatch (CspProjectException ex) when (ex.Message.Contains(\"has no Main method\")) { /* add a static Main to the class or point the project at another class */ }","preventionTips":["Every class declared as a project main class must define a static Main.","Do not rename or remove Main during refactors without updating the project.","Point mainClass at the actual entry-point class, not helper types."],"tags":["csp","entry-point","main-method","reflection"],"backgroundTag":"missing-main-method","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}