{"record":{"id":"e0527b1a460a5156","repo":"dotnet/maui","slug":"xc0004","errorCode":"XC0004","errorMessage":"Missing default constructor for \"{0}\".","messagePattern":"Missing default constructor for \"(.+?)\"\\.","errorType":"error_code","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledConverters/RDSourceTypeConverter.cs","lineNumber":103,"sourceCode":"\t\t\tforeach (var instruction in (new UriTypeConverter()).ConvertFromString(value, context, node))\n\t\t\t\tyield return instruction; //the Uri\n\t\t}\n\n\t\tprivate static IEnumerable<Instruction> CreateResourceDictionaryType(\n\t\t\tILContext context,\n\t\t\tModuleDefinition currentModule,\n\t\t\tModuleDefinition module,\n\t\t\tBaseNode node,\n\t\t\tElementNode rdNode,\n\t\t\tTypeReference resourceTypeRef,\n\t\t\tVariableDefinition uriVarDef)\n\t\t{\n\t\t\tvar resourceType = module.ImportReference(resourceTypeRef).Resolve();\n\n\t\t\t// validate that the resourceType has a default ctor\n\t\t\tvar hasDefaultCtor = resourceType.Methods.Any(md => md.IsConstructor && !md.HasParameters);\n\t\t\tif (!hasDefaultCtor)\n\t\t\t\tthrow new BuildException(BuildExceptionCode.ConstructorDefaultMissing, node, null, resourceType);\n\n\t\t\tvar method = module.ImportMethodReference(\n\t\t\t\tcontext.Cache,\n\t\t\t\t(\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls\", \"ResourceDictionary\"),\n\t\t\t\tmethodName: \"SetAndCreateSource\",\n\t\t\t\tparameterTypes: new[] { (\"System\", \"System\", \"Uri\") });\n\n\t\t\tvar genericInstanceMethod = new GenericInstanceMethod(method);\n\t\t\tgenericInstanceMethod.GenericArguments.Add(resourceType);\n\n\t\t\t// public void rd.SetAndCreateSource<TResourceType>(Uri value)\n\t\t\tforeach (var instruction in context.Variables[rdNode].LoadAs(context.Cache, currentModule.GetTypeDefinition(context.Cache, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls\", \"ResourceDictionary\")), currentModule))\n\t\t\t\tyield return instruction;\n\t\t\tyield return Create(Ldloc, uriVarDef);\n\t\t\tyield return Create(Callvirt, currentModule.ImportReference(genericInstanceMethod));\n\t\t}\n\n\t\tprivate static IEnumerable<Instruction> LoadResourceDictionaryFromSource(","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/RDSourceTypeConverter.cs#L85-L121","documentation":"XC0004 ConstructorDefaultMissing thrown by RDSourceTypeConverter.CreateResourceDictionaryType when the type associated with a compiled ResourceDictionary Source has no parameterless constructor. The converter resolves the resource type from the XamlResourceIdAttribute, then checks if any constructor on it has zero parameters. If none exists, the build fails because ResourceDictionary.SetAndCreateSource<T> requires 'new T()'.","triggerScenarios":"A XAML ResourceDictionary code-behind class (e.g. a partial class for a merged dictionary) that defines only parameterized constructors and no implicit default constructor. The class is referenced via Source and the compiler tries to instantiate it at compile time but cannot.","commonSituations":"Adding a constructor with parameters to a ResourceDictionary subclass without also keeping a parameterless one. The default constructor was removed or made private. Using a class that inherits from ResourceDictionary but whose base requires arguments.","solutions":["Add an explicit public parameterless constructor to the ResourceDictionary subclass.","Remove or supplement any parameterized-only constructors so 'new T()' is valid.","Ensure the parameterless constructor is public (not private/internal) so the generated code can call it."],"exampleFix":"// before\npublic partial class MyResources : ResourceDictionary\n{\n    public MyResources(string theme) { ... }\n}\n\n// after\npublic partial class MyResources : ResourceDictionary\n{\n    public MyResources() { InitializeComponent(); }\n    public MyResources(string theme) { ... }\n}","handlingStrategy":"validation","validationCode":"// Validate that a ResourceDictionary subclass has a public parameterless constructor\nstatic bool HasDefaultConstructor(Type type)\n    => type.GetConstructors()\n           .Any(c => c.IsPublic && c.GetParameters().Length == 0);","typeGuard":"static bool IsInstantiableResourceDictionary(Type type)\n    => typeof(ResourceDictionary).IsAssignableFrom(type)\n       && type.GetConstructors().Any(c => c.IsPublic && c.GetParameters().Length == 0);","tryCatchPattern":null,"preventionTips":["Always keep a public parameterless constructor on ResourceDictionary subclasses.","The default constructor should call InitializeComponent() for XAML-loaded dictionaries.","Avoid making the parameterless constructor private or internal."],"tags":["xaml","maui","xamlc","resourcedictionary","constructor","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}