How to Resolve Error "CS0167: The delegate 'delegate' is missing the Invoke method" in C#
The Compiler Error CS0167 is a rare Metadata or Environment error. The message reads: "The delegate 'DelegateName' is missing the Invoke method".
In .NET, a Delegate is essentially a class that inherits from System.MulticastDelegate. When you define a delegate, the compiler automatically generates three methods for it: Invoke, BeginInvoke, and EndInvoke. When you call a delegate in code (e.g., myHandler()), the compiler translates this into a call to myHandler.Invoke().
CS0167 indicates that the compiler recognizes the type as a Delegate, but when it inspected the type's definition (usually inside a referenced DLL), the required Invoke method was physically missing. This almost always indicates a corrupted build, a version mismatch, or an improperly imported library.
Understanding Delegate Internals
You don't see the Invoke method in your C# code, but it exists in the compiled Intermediate Language (IL).
Your Code:
public delegate void MyDelegate(string msg);
Compiled IL (Pseudo-code):
public class MyDelegate : MulticastDelegate
{
// The compiler MUST generate this:
public virtual void Invoke(string msg) { ... }
}
If the compiler tries to call Invoke but cannot find it in the metadata of the referenced assembly, CS0167 is thrown. Since you cannot manually "delete" this method in C#, the error implies the definition file is broken.
Scenario 1: Corrupted Build Artifacts (Most Common)
The most frequent cause of this error is a synchronized build failure. For example, Project A defines the delegate, and Project B uses it. If the build process was interrupted, or if Project B is referencing an outdated/cached version of Project A's DLL that is malformed, the metadata may be incomplete.
Symptoms
- The code looks syntactically perfect.
- IntelliSense might show the delegate correctly.
- The error appears suddenly after a crash or git merge.
Solution: Clean and Rebuild
You need to force the compiler to regenerate the metadata for the delegate definition.
- Close Visual Studio (or your IDE).
- Delete Artifacts: Navigate to your solution folder and manually delete the
binandobjfolders for all projects in the solution. - Reopen and Rebuild: Open the solution and select Build > Rebuild Solution.
Simple "Rebuild" in Visual Studio sometimes skips files it thinks are up-to-date. Manually deleting the folders is the only way to guarantee a fresh metadata generation.
Scenario 2: Invalid IL or Non-C# Libraries
If you are referencing a DLL that was not written in C# (e.g., C++/CLI, IL Assembly, or a custom compiler), that library might have defined a type that inherits from System.Delegate but failed to provide the required Invoke method signature.
This can also happen if you are using IL Weaving tools (like PostSharp or Fody) that modify your assembly after compilation. If the tool bugs out, it might strip the Invoke method.
The Checklist:
- Check References: Are you referencing a custom, third-party DLL? Try updating it to the latest version.
- Check Post-Processing: Are you using tools that modify IL? Try disabling them temporarily.
- Check Runtime Versions: Ensure you aren't mixing very old .NET Framework (e.g., 1.1) binaries with modern .NET SDKs in incompatible ways.
Conclusion
CS0167 is rarely a mistake in your source code. It is a signal that the definitions your compiler is looking at are corrupted.
- Don't change your code: There is no code fix for "missing Invoke" because you didn't write
Invokein the first place. - Focus on the Environment: The issue lies in the
bin/objfolders or referenced DLLs. - Perform a Hard Clean: Delete temporary build folders and rebuild to restore valid metadata.