{"record":{"id":"0321ab873038ae4e","repo":"dotnet/efcore","slug":"you-must-provide-a-dbcontext-t4-file-in-order-to-s","errorCode":null,"errorMessage":"You must provide a DbContext.t4 file in order to scaffold using custom templates.","messagePattern":"You must provide a DbContext\\.t4 file in order to scaffold using custom templates\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Scaffolding/Internal/TextTemplatingModelGenerator.cs","lineNumber":115,"sourceCode":"                { \"ProjectDefaultNamespace\", options.RootNamespace }\n            }\n        };\n        var contextTemplate = Path.Combine(options.ProjectDir!, TemplatesDirectory, DbContextTemplate);\n\n        string generatedCode;\n        if (File.Exists(contextTemplate))\n        {\n            host.TemplateFile = contextTemplate;\n\n            generatedCode = Engine.ProcessTemplateAsync(File.ReadAllText(contextTemplate), host).GetAwaiter().GetResult();\n            CheckEncoding(host.OutputEncoding);\n            HandleErrors(host);\n        }\n        else\n        {\n            if (!string.Equals(options.Language, \"C#\", StringComparison.OrdinalIgnoreCase))\n            {\n                throw new OperationException(DesignStrings.NoContextTemplate);\n            }\n\n            var defaultContextTemplate = new CSharpDbContextGenerator { Host = host, Session = host.Session };\n            defaultContextTemplate.Initialize();\n\n            generatedCode = defaultContextTemplate.TransformText();\n\n            foreach (CompilerError error in defaultContextTemplate.Errors)\n            {\n                _reporter.Write(error);\n            }\n\n            if (defaultContextTemplate.Errors.HasErrors)\n            {\n                throw new OperationException(DesignStrings.ErrorGeneratingOutput(defaultContextTemplate.GetType().Name));\n            }\n        }\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Scaffolding/Internal/TextTemplatingModelGenerator.cs#L97-L133","documentation":"Thrown when scaffolding with custom templates is requested for a language other than C# but no DbContext.t4 is supplied. EF Core only ships a built-in fallback DbContext generator for C# (CSharpDbContextGenerator); for any other language the user must provide the DbContext.t4 template.","triggerScenarios":"In GenerateModel, options.Language is not \"C#\" (case-insensitive) and no DbContext.t4 file exists at the expected template path, so the else branch throws NoContextTemplate.","commonSituations":"Attempting to scaffold VB.NET or F# contexts without supplying custom templates. Forgetting to ship the DbContext.t4 alongside the rest of a VB/F# template set. Setting options.Language to a non-C# value by accident.","solutions":["Provide a DbContext.t4 template authored for the target language (VB.NET / F#).","Set options.Language to \"C#\" if C# output is acceptable, to use the built-in fallback generator.","Use a community template pack that ships DbContext.t4 for VB.NET/F# scaffolding."],"exampleFix":"// before\noptions.Language = \"VB\";   // no DbContext.t4 present\n// after - option A: supply template\n//   CodeTemplates/EFCore/DbContext.t4   (VB version)\n// after - option B: use C# fallback\noptions.Language = \"C#\";","handlingStrategy":"validation","validationCode":"bool isCSharp = string.Equals(options.Language, \"C#\", StringComparison.OrdinalIgnoreCase);\nbool hasCtxTemplate = File.Exists(contextTemplate);\nif (!isCSharp && !hasCtxTemplate)\n    throw new InvalidOperationException(\"Provide DbContext.t4 for non-C# languages\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ship a DbContext.t4 for every language you scaffold.","Default options.Language to \"C#\" when C# output is acceptable.","Validate the template set per language in a pre-scaffold check."],"tags":["t4","templating","scaffolding","design-time","language"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}