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
- Pass a specific context name to 'dbcontext info' instead of the wildcard: '--context MyContext'.
- Omit --context entirely if there is exactly one context; the tool will pick it.
- 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
- Never pass '*' to 'dbcontext info'; it is single-context only.
- Pass an explicit context name or omit --context when exactly one exists.
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
- No DbContext was found in assembly '{assembly}'. Ensure that
- No type deriving from DbContext was found. Add [assembly: Db
- Unable to create a 'DbContext' of type '{contextType}'. The
- The exception '{rootException}' was thrown while attempting
- More than one DbContext was found. Specify which one to use.
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/f3ad5c9b69065932.
Report an issue: GitHub.