dotnet/efcore · error · FileNotFoundException

Failed to resolve type for directive processor {name}.

Error message

Failed to resolve type for directive processor {name}.

What it means

Thrown by the T4 text-templating host when the templating engine asks it to resolve a directive processor by name and the host has no registration for it. EF Core's built-in host only supports the directives it ships; any other directive processor name yields a FileNotFoundException so the template fails fast instead of silently emitting broken code.

Source

Thrown at src/EFCore.Design/Scaffolding/Internal/TextTemplatingEngineHost.cs:216

        {
            return Assembly.Load(assemblyReference).Location;
        }
        catch
        {
        }

        // TODO: Expand variables?
        return assemblyReference;
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual Type ResolveDirectiveProcessor(string processorName)
        => throw new FileNotFoundException(DesignStrings.UnknownDirectiveProcessor(processorName));

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual string ResolveParameterValue(string directiveId, string processorName, string parameterName)
        => string.Empty;

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual string ResolvePath(string path)
        => !Path.IsPathRooted(path) && Path.IsPathRooted(TemplateFile)

View on GitHub (pinned to 3a2006ef56)

Solutions

  1. Remove the unsupported `<#@ directive processor="..." #>` directive from your .t4 template; EF Core only supports self-contained templates.
  2. Replace the directive processor logic with inline helper code or a <#+ class function block #> in the template.
  3. If you truly need a custom processor, port the template to the standalone T4 host or to EF Core's CSharpDbContextGenerator model.
  4. Diff your template against the EF Core default templates to find unsupported directives.

Example fix

// before
<#@ template language="C#" #>
<#@ directive processor="PropertyProcessor" #>
// after
<#@ template language="C#" #>
<# // inline any logic the processor provided #>
Defensive patterns

Strategy: validation

Validate before calling

// Scan your .t4 templates for unsupported directives before scaffolding
var disallowed = new[] { "directive processor" };
foreach (var t4 in Directory.GetFiles(templatesDir, "*.t4"))
  foreach (var line in File.ReadAllLines(t4))
    if (disallowed.Any(d => line.Contains(d)))
      Console.Error.WriteLine($"Unsupported directive in {t4}: {line}");

Prevention

When it happens

Trigger: A custom DbContext.t4 / EntityTypeConfiguration.t4 template contains a `<#@ directive processor="..." #>` directive whose processor name is not registered in the EF Core TextTemplatingEngineHost. Reached when TextTemplatingModelGenerator compiles the user template.

Common situations: Copying a T4 template that depends on Visual Studio's directive processors (e.g. the VS host or a custom data directive processor) into an EF Core scaffolding templates folder. Editing a template on a machine without the referenced processor assembly.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/a46ce93698ef4e5c. Report an issue: GitHub.