{"record":{"id":"2eb5540959aa2c33","repo":"dotnet/wpf","slug":"error-project-does-not-contain-type-0","errorCode":null,"errorMessage":"Error: Project does not contain type '{0}'","messagePattern":"Error: Project does not contain type '(.+?)'","errorType":"exception","errorClass":"CspProjectException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WpfGfx/tools/csp/Project.cs","lineNumber":194,"sourceCode":"        /// <summary>\n        /// Execute the Main function. (A static member of a certain hardcoded class).\n        /// </summary>\n        internal int ExecuteMain(\n            string sMainClass,\n            string[] parameters\n            )\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();","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WpfGfx/tools/csp/Project.cs#L176-L212","documentation":"Project.ExecuteMain in the csp tool looks up the project's main class in the compiled assembly via _assembly.GetType(sMainClass) and throws CspProjectException when the type cannot be found. This means the project file declares a main class that is not present in the built assembly, so the tool cannot invoke its entry point.","triggerScenarios":"Running csp on a project whose declared main class name (namespace-qualified) does not match any type in the assembly: typo in the project config, class renamed/deleted, or the assembly is stale/missing the class.","commonSituations":"Renaming a namespace or class without updating the project file; running against an out-of-date build output; wrong casing of the type name; pointing csp at the wrong DLL.","solutions":["Check the fully-qualified type name in the project file against the actual class (case-sensitive, includes namespace).","Rebuild the assembly so it contains the declared main class.","Verify csp is loading the correct assembly file for this project.","Fix the project's main-class setting after any rename or namespace change."],"exampleFix":"// before (project file)\n<mainClass>MyTools.OldRunner</mainClass>\n// after\n<mainClass>MyTools.Runner</mainClass>","handlingStrategy":"validation","validationCode":"var asm = Assembly.LoadFrom(assemblyPath);\nvar mainType = asm.GetType(sMainClass, throwOnError: false);\nif (mainType == null)\n    throw new Exception($\"Type '{sMainClass}' not found in {assemblyPath}\");","typeGuard":"static bool AssemblyContainsType(Assembly asm, string fullName) => asm != null && asm.GetType(fullName, throwOnError: false) != null;","tryCatchPattern":"try { project.ExecuteMain(); }\ncatch (CspProjectException ex) when (ex.Message.Contains(\"does not contain type\")) { /* fix mainClass name in project file and rebuild */ }","preventionTips":["Keep the project file's mainClass setting in sync with class/namespace renames.","Rebuild before running csp so the assembly matches the project.","Use fully-qualified, correctly-cased type names."],"tags":["csp","type-not-found","reflection","project-config"],"backgroundTag":"class-not-found","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"}