Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

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 an Interceptor Silently Skipping an Overloaded Call

- 21.11.26 - ErcanOPAK

🔧 C#: Fix an Interceptor Silently Skipping an Overloaded Call

C# interceptors attach to a call site by its exact file path, line, and column, and an InterceptsLocation attribute targets one specific call expression with an exact method signature. If the intercepted method has multiple overloads and a refactor changes which overload a call site binds to — say, a new overload becomes a better match for the same arguments — the call site’s location is unchanged but the method it now resolves to is different, so the interceptor’s recorded signature no longer matches and the compiler silently stops applying it.

🔎 The Problem

// Before: only one overload existed, interceptor generated for it
cache.Get("key"); // binds to Get(string), intercepted for caching

// A new overload is added later:
public T Get<T>(string key, T fallback) => ...;
public T Get<T>(string key) => ...; // original, still the best match here

// Call site location unchanged, overload resolution unchanged too -
// but if a stale interceptor assembly still references the OLD
// signature shape, the compiler drops it silently, no diagnostic

✅ Fix: Regenerate Interceptors Whenever Overloads Change

  • Regenerate interceptors as part of your build whenever overloads of an intercepted method change, rather than caching previously-generated interceptor code, since a stale interceptor doesn’t fail loudly — it just stops being applied.
  • Add a runtime or test-time assertion that the behavior an interceptor was supposed to provide (a caching layer, a logging wrapper) is actually happening for the call sites that should have it, rather than trusting that the interceptor attribute being present in generated code means it’s active.
  • When adding a new overload to a method with call sites relying on interception, check whether any existing call sites’ overload resolution changes as a result, since that’s the specific condition that breaks a previously-working interceptor without any compiler diagnostic.

🚨 Why This Is Dangerous

  • A silently-skipped interceptor can disable an optimization or cross-cutting behavior — caching, telemetry, validation — that the rest of the system was built assuming is always active, and because there’s no compiler error, the gap can go unnoticed until something downstream behaves as if that behavior never ran.

An interceptor activates on an exact match between its recorded call site and what that call site actually resolves to — change which overload binds there, and the interceptor doesn’t warn you, it just quietly stops being part of the program.

— C# Best Practice

Related posts:

The Hidden Cost of Exceptions as Flow Control

The Hidden Cost of Exceptions as Flow Control

C#: Fix a Monitor Lock Held Across an await by the Wrong Thread

C#: Fix a Monitor Lock Held Across an await by the Wrong Thread

C#: Use Nullable Value Types for Optional Values

C#: Use Nullable Value Types for Optional Values

Views: 2

Post navigation

Git: Fix a Submodule Pointing to a Commit That No Longer Exists
CSS: Fix a Scroll-Driven Animation Running Only on First Load

Leave a Reply Cancel reply

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

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

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

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • AÄŸ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store
  • WordPress: Fix a Navigation Block Losing Submenu Items After Sync
  • Visual Studio: Fix CodeLens Reference Counts Stuck at Stale Numbers
  • C#: Fix a UTF-8 String Literal Behaving Differently in a Switch
  • Photoshop: Fix a Liquify Mesh Snapping Back on a Smart Object
  • The AI Prompt That Turns a Crash Dump Into a Short Repro Script

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • AÄŸ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Social

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