Unity-Technologies/UnityCsReference · error · InvalidOperationException
Could not create a valid delegate from method marked: [RootE
Error message
Could not create a valid delegate from method marked: [RootEditorAttribute] with signature: ({signature}) What it means
When registering root editors, the code tries to build either a plain handler or a metadata handler from a method marked [RootEditorAttribute]. If neither delegate construction path succeeds, it captures the method's parameter signature and throws InvalidOperationException, so a mis-signed handler fails loudly at registration rather than silently never firing.
Source
Thrown at Editor/Mono/Inspector/Core/RootEditor.cs:154
desc.usesMetaData = false;
desc.rootEditorHandler = handler;
rootEditors.Add(desc);
}
else if (Delegate.CreateDelegate(typeof(RootEditorWithMetaDataHandler), candidate, false) is RootEditorWithMetaDataHandler handlerWithMetaData)
{
desc.usesMetaData = true;
desc.rootEditorWithMetaDataHandler = handlerWithMetaData;
rootEditorsWithMetaData.Add(desc);
}
else
{
var parameters = candidate.GetParameters();
var signature = parameters is { Length: > 0 }
#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.
? string.Join(", ", parameters.Select(p => p.ParameterType.FullName))
#pragma warning restore UA2001
: string.Empty;
throw new InvalidOperationException($"Could not create a valid delegate from method marked: [{nameof(RootEditorAttribute)}] with signature: ({signature})");
}
}
kSRootEditor.Clear();
// Adding the root editors with metadata first to take precedence over the general version
kSRootEditor.AddRange(rootEditorsWithMetaData);
kSRootEditor.AddRange(rootEditors);
ListPool<RootEditorDesc>.Release(rootEditors);
ListPool<RootEditorDesc>.Release(rootEditorsWithMetaData);
}
}
}
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Match the exact delegate signature expected by RootEditorAttribute (inspect the accepted handler/metadata-handler parameter types in the registration code above the throw).
- Ensure parameters are passed by the types the attribute expects (e.g. the metadata variant needs the metadata argument type).
- Remove [RootEditorAttribute] from methods that are not intended to be root editor handlers.
- Check the thrown signature string to see exactly which parameter types were rejected.
Example fix
// before: signature mismatch -> InvalidOperationException with the printed signature
[RootEditor] static void MyHandler(GameObject go, int extra) { } // wrong params
// after: match the expected delegate parameter shape
[RootEditor] static void MyHandler(RootEditorContext ctx) { } Defensive patterns
Strategy: validation
Validate before calling
// before attributing a method, verify it matches an accepted handler signature var ps = method.GetParameters(); bool ok = ps.Length == 0 || HandlerParameterTypes.Any(t => ps.Length == 1 && ps[0].ParameterType == t); if (!ok) return; // skip rather than register a bad handler
Type guard
static bool IsValidRootEditorSignature(MethodInfo m)
{
var p = m.GetParameters();
return p.Length == 0 || (p.Length == 1 && IsAcceptedContextType(p[0].ParameterType));
} Prevention
- Keep [RootEditor]-marked methods to the documented delegate signatures.
- When refactoring handlers, re-read the registration code to confirm the accepted parameter types.
- Avoid speculative attribute application; remove the attribute if a method is not a real handler.
When it happens
Trigger: A method decorated with [RootEditorAttribute] has a parameter list that matches neither the expected root-editor delegate nor the metadata variant (e.g. wrong parameter types, wrong count, missing required context parameter).
Common situations: Authoring a custom root editor handler with an incorrect signature. Refactoring a handler and changing its parameters without updating the attribute contract. Copy-pasting a handler pattern from a different Unity version whose delegate signature differs.
Related errors
- BuiltinBakedReflectionSystem
- Delegate already registered for dropDestinationId:{dropDstId
- Editor type '{editorType}' does not derive from UnityEditor.
- Given rpAssetType must derive from RenderPipelineAsset
- The specified assembly file could not be found.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/20b1cd0689f32e1e.
Report an issue: GitHub.