dotnet/efcore · error · OperationException
No files were generated in directory '{outputDirectoryName}'
Error message
No files were generated in directory '{outputDirectoryName}'. The following file(s) already exist(s) and must be made writeable to continue: {readOnlyFiles}. What it means
Thrown in CompiledModelScaffolder.WriteFiles (line 90, resource ReadOnlyFiles) when writing the compiled-model output files: some target files already exist and are marked read-only (FileAttributes.ReadOnly), so they cannot be overwritten. Rather than partially writing files, EF collects all read-only paths and throws an OperationException listing them. No files in the conflicting set are written.
Source
Thrown at src/EFCore.Design/Scaffolding/Internal/CompiledModelScaffolder.cs:90
var savedFiles = new List<string>();
foreach (var file in scaffoldedModel)
{
var fullPath = Path.Combine(outputDir, file.Path);
if (File.Exists(fullPath)
&& File.GetAttributes(fullPath).HasFlag(FileAttributes.ReadOnly))
{
readOnlyFiles.Add(file.Path);
}
else
{
File.WriteAllText(fullPath, file.Code, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
savedFiles.Add(fullPath);
}
}
return readOnlyFiles.Count != 0
? throw new OperationException(
DesignStrings.ReadOnlyFiles(
outputDir,
string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, readOnlyFiles)))
: (IReadOnlyList<string>)savedFiles;
}
}
View on GitHub (pinned to dbf9771522)
Solutions
- Clear the read-only attribute on the listed files (e.g. chmod +w / attrib -r) so they can be overwritten.
- Delete the existing output files in the target directory before regenerating.
- Use the scaffolder's force/overwrite option if invoking programmatically, or write to a fresh output directory.
- If a VCS marks files read-only, ensure generated output is excluded from VCS or that the VCS is configured not to set read-only.
Example fix
# before: read-only files block generation chmod u+w obj/CompiledModels/*.cs # Linux/mac attrib -r obj\CompiledModels\*.cs # Windows # then re-run dotnet ef dbcontext optimize
Defensive patterns
Strategy: validation
Validate before calling
// Clear read-only attributes on existing output files before writing
foreach (var f in Directory.GetFiles(outputDir, "*.cs", SearchOption.AllDirectories))
if ((File.GetAttributes(f) & FileAttributes.ReadOnly) != 0)
File.SetAttributes(f, File.GetAttributes(f) & ~FileAttributes.ReadOnly); Try / catch
try { CompiledModelScaffolder.WriteFiles(model, outputDir); }
catch (OperationException ex) when (ex.Message.Contains("must be made writeable"))
{ /* clear read-only flags on listed files or use a fresh directory, then retry */ } Prevention
- Generate into a clean directory or clear read-only flags first.
- Exclude generated output from VCS systems that set read-only attributes.
- Use the overwrite/force path when available.
When it happens
Trigger: Running compiled-model scaffolding into a directory where one or more output files already exist with the read-only attribute set. For each file, if File.Exists and attributes include ReadOnly, it is added to readOnlyFiles; if any exist at the end, the ReadOnlyFiles OperationException is thrown.
Common situations: Files checked into source control with read-only attributes (some VCS mark files read-only), or generated previously and then locked. Running on a filesystem/CI that marks output read-only. Re-running 'dotnet ef dbcontext optimize' without clearing previous read-only outputs.
Related errors
- Compound assignment not supported yet.
- The entity type '{entityType}' has a custom constructor bind
- The entity type '{entityType}' has a query filter configured
- The property '{entityType}.{property}' has a value generator
- You cannot add a migration with the name 'Migration'.
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/bfd7661dae5b5e88.
Report an issue: GitHub.