dotnet/efcore · error · OperationException
No files were generated in directory
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 by CompiledModelScaffolder when writing the generated compiled-model files and one or more target paths already exist with the read-only file attribute. The scaffolder refuses to overwrite read-only files, collects the offending paths, and throws OperationException (DesignStrings.ReadOnlyFiles) listing them so they can be made writable.
Solutions
- Remove the read-only attribute from the listed files: chmod +w (Linux/mac) or attrib -R (Windows), or delete them.
- Clear the output directory before regenerating.
- Ensure the output directory is writable by the user running the tool.
Example fix
# before: files are read-only chmod -R u+w OutputDir/ # or remove and regenerate rm -rf OutputDir/ && dotnet ef dbcontext optimize
Defensive patterns
Strategy: validation
Validate before calling
// Ensure output files are writable before scaffolding
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 { scaffolder.Save(outputDir); }
catch (OperationException ex) when (ex.Message.Contains("writeable"))
{ /* chmod/attrib the listed files, or delete the directory and retry */ } Prevention
- Write compiled-model output to a directory not under a read-only source-control attribute.
- Clear or chmod the output directory before regenerating.
- In CI, write to a fresh working directory.
When it happens
Trigger: Running 'dotnet ef dbcontext optimize' (or programmatic compiled-model scaffolding) into a directory where a previous generation produced files that are now read-only.
Common situations: Files checked into source control that applies a read-only attribute; output generated on one OS/filesystem and copied to another; CI that marks artifacts read-only; a previous --force run left read-only files.
Related errors
- No backing field was found for property
- The entity type ' ' has a custom constructor binding…
- The entity type ' ' has a query filter configured. Compiled…
- The property ' . ' has a value generator configured. Use '…
- A type-qualified method call requires an instance…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/bfd7661dae5b5e88.
Report an issue: GitHub.
Appendix: 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 3a2006ef56)