Why Your .NET MCP Tool Classes Crash at Runtime (And the Two-Line Fix)
If you're building MCP servers in .NET with instance-based tool classes — the kind that take ILogger<T> , HttpClient , or a repository through constructor injection — there's a good chance you've already hit this at runtime: System.Reflection.TargetException: Non-static method requires a target. No warning at startup. No compile-time error. Just a crash the moment an AI model calls your tool in…
When creating MCP servers in .NET using instance-based tool classes, such as those taking ILogger<T>, HttpClient, or repositories through constructor injection, users may have encountered a runtime crash. This issue is not flagged by warnings or compile-time errors, leading to silence at startup and a crash during production. The source material explains the root cause and provides a two-line fix in DotnetFastMCP v2.1 to address this problem.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.