Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
C#

C#: Fix a Params Array Overload That Silently Binds to the Wrong Method

- 27.09.26 - ErcanOPAK

🔧 The New Overload That Quietly Stole Calls From the Old One

C#’s overload resolution always prefers a non-params overload over a params array overload when both are an equally valid match for a call – which is exactly correct in isolation, but means adding a brand-new, more specific overload to an existing method group can silently redirect calls that used to go to the params version, without touching a single line at any of those call sites. Nothing fails to compile; the code just quietly starts doing something else.

🔎 The Problem

public static class Logger
{
    public static void Log(string message, params object[] args)
        => Console.WriteLine(string.Format(message, args));
}

// Every call site in the codebase uses this form:
Logger.Log("User {0} failed with {1}", userId, lastException);

// Months later, someone adds a convenience overload for the common
// "message plus one exception" case:
public static void Log(string message, Exception ex)
    => Console.WriteLine($"{message}: {ex.Message}");

// Every existing call that passed exactly one Exception as the second
// argument NOW silently binds to the new overload instead of the old
// params one - the format placeholder "{0}" is never substituted, and
// the original message text (with userId) is gone entirely.

✅ Fix: Treat a New Overload as a Binding-Compatibility Change

  • Before adding a new, more specific overload to an existing method group, searching the codebase for every call site that could match its exact parameter shape is worth doing deliberately – a params overload is exactly the situation where a new sibling overload can silently reroute calls that were never touched.
  • Giving the new overload a distinct name (LogException(…) instead of another Log(…) overload) removes the ambiguity entirely – it costs a slightly less elegant call site, in exchange for a guarantee that existing calls can never be silently rebound by a future addition.
  • A quick regression check specifically for the params call sites (confirming the formatted output still contains the substituted values, not just that the code compiles) catches this class of bug immediately, since the compiler gives no warning at all when overload resolution shifts.

⚠️ Why the Compiler Never Complains

  • This isn’t a compile error or even a warning, because from the compiler’s point of view nothing is wrong – every call still has a valid, unambiguous target method, it’s just a different one than it used to resolve to before the new overload existed.
  • The bug is easiest to introduce specifically in mature, widely-used method groups (logging, formatting, validation helpers) where a params overload has quietly become the catch-all for years, precisely because those are the ones most likely to eventually get a new, more specific sibling added for convenience.

A params overload is a catch-all only until something more specific shows up – and when it does, every call that used to fall into the catch-all moves without asking permission first.

— C# Best Practice

Related posts:

Why record Types Reduce Bugs in DTOs

C#: Use Native AOT to Compile .NET Apps to Single Executables

ConfigureAwait(false) — When It Actually Matters

Post Views: 2

Post navigation

The AI Prompt That Reviews Your Retry and Backoff Logic for Silent Infinite Loops
Docker: Fix a Container That Can’t Write to a Volume Mounted From the Host

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (951)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (836)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (624)
  • Add Constraint to SQL Table to ensure email contains @ (590)
  • Average of all values in a column that are not zero in SQL (553)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (526)
  • Find numbers with more than two decimal places in SQL (468)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (951)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (836)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com