dotnet/efcore · error · OperationException

The wildcard '*' can only be used with commands that run for

Error message

The wildcard '*' can only be used with commands that run for all contexts found. Specify a context name for this command.

What it means

Thrown by DbContextOperations.GetContextInfo when contextType equals the wildcard '*'. GetContextInfo returns information about a single context and cannot meaningfully iterate all contexts, so the wildcard (used by drop/optimize for 'all contexts') is explicitly rejected here.

Source

Thrown at src/EFCore.Design/Design/Internal/DbContextOperations.cs:456

        return !string.IsNullOrWhiteSpace(subPath)
            ? string.Join(
                ".",
                subPath.Split(
                    [Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar], StringSplitOptions.RemoveEmptyEntries))
            : null;
    }

    /// <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 ContextInfo GetContextInfo(string? contextType, string? connectionString = null)
    {
        if (contextType == "*")
        {
            throw new OperationException(DesignStrings.WildcardNotSupported);
        }

        using var context = CreateContext(contextType);

        if (connectionString != null)
        {
            context.Database.SetConnectionString(connectionString);
        }

        var info = new ContextInfo { Type = context.GetType().FullName! };

        var provider = context.GetService<IDatabaseProvider>();
        info.ProviderName = provider.Name;

        if (((IDatabaseFacadeDependenciesAccessor)context.Database).Dependencies is IRelationalDatabaseFacadeDependencies)
        {
            try
            {

View on GitHub (pinned to dbf9771522)

Solutions

  1. Pass a specific context name to 'dbcontext info' instead of the wildcard: '--context MyContext'.
  2. Omit --context entirely if there is exactly one context; the tool will pick it.
  3. If you need info on multiple contexts, call the command once per context name.

Example fix

# before
dotnet ef dbcontext info --context *   # throws WildcardNotSupported

# after
dotnet ef dbcontext info --context MyContext
Defensive patterns

Strategy: validation

Validate before calling

if (contextType == "*")
    throw new InvalidOperationException("GetContextInfo requires a single context; pass a specific name.");
ops.GetContextInfo(contextType, connectionString);

Prevention

When it happens

Trigger: Calling 'dotnet ef dbcontext info --context *' or invoking GetContextInfo with a wildcard context name. The method requires exactly one context.

Common situations: Copy-pasting a wildcard '--context *' from a database-drop or optimize command into a 'dbcontext info' call. Scripting that passes '*' uniformly across EF commands without realizing info is single-context.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/f3ad5c9b69065932. Report an issue: GitHub.