How a decompiler reads C# interceptors
C# interceptors redirect a call at compile time, leaving no marker at the call site — so the only trace is an InterceptsLocation attribute whose base64 blob Glass decodes back into a content hash, a source position, and the intercepted method name.
You decompile a release build, open Program.cs, and find a call that no longer goes where the source said it would. The code reads client.GetForecast("NYC"), but the IL calls a static method in a generated file class you have never heard of. Nobody edited the source. The compiler rewired the call — and it left almost nothing behind to explain why.
This is a C# interceptor. It is one of the few language features that changes which method a call binds to after you have written the call, and it is deliberately invisible at the call site. For a decompiler that is a problem: there is no opcode, no modifier, no marker that says “this call was redirected.” Understanding your own build means knowing where the only surviving evidence lives and how to read it.
The real question
An interceptor is a method, supplied by a source generator, that the compiler substitutes for a specific call at a specific source location. ASP.NET Core minimal APIs use this to replace reflection-based MapGet plumbing with generated, strongly-typed request handlers; configuration binders and mapping libraries use it the same way. The feature is opt-in behind <InterceptorsNamespaces> in the project file.
Here is the user code and the generated interceptor:
// Program.cs (what you wrote)
var client = new WeatherClient();
var forecast = client.GetForecast("NYC"); // ← compiler redirects this call
// WeatherClient.g.cs (emitted by a source generator)
namespace Generated;
file static class WeatherInterceptors
{
[global::System.Runtime.CompilerServices.InterceptsLocation(
1, "khAcU2t0b2tlbgAAAABQAAAAUHJvZ3JhbS5jcw==")]
public static Forecast GetForecast_Fast(this WeatherClient client, string city)
{
// generated fast path, no reflection
}
}
The compiler sees that GetForecast_Fast claims the location of the GetForecast call and emits a call to the interceptor instead. The question a decompiler has to answer is: given only the assembly, how do you recover the fact that interception happened, and what the original target was?
The call site tells you nothing
Start where your instinct says to look — the call itself. The emitted IL for that line is an ordinary call:
ldloc.0 // client
ldstr "NYC"
call class Generated.Forecast
Generated.WeatherInterceptors::GetForecast_Fast(
class WeatherClient, string)
There is no WeatherClient::GetForecast anywhere in this method body. The original target is not referenced, not commented, not flagged. As far as the IL is concerned, you simply wrote a call to GetForecast_Fast. A decompiler that renders this faithfully will show you exactly that — which is correct, because it is what executes, but it hides the rewrite. Interception is a bind-time decision baked into the call token; nothing survives at the call site to undo it.
So the only place the redirection is recorded is on the interceptor method, as a custom attribute.
Decoding the InterceptsLocation blob
InterceptsLocationAttribute is emitted into metadata like any other custom attribute. The current (version 1) form takes two arguments — an int version and a string data blob:
.method public hidebysig static class Forecast
GetForecast_Fast(class WeatherClient client, string city) cil managed
{
.custom instance void
System.Runtime.CompilerServices.InterceptsLocationAttribute::.ctor(int32, string)
= ( 01 00 01 00 00 00 24 6B 68 41 63 55 32 74 30 62 32 74 6C 62 ... 00 00 )
Read that CA blob by the ECMA-335 rules. 01 00 is the prolog. 01 00 00 00 is the first fixed argument, the int32 version 1. Then comes the string argument as a SerString: a compressed-integer length (0x24 = 36 bytes) followed by the UTF-8 bytes of the base64 text. The trailing 00 00 is the named-argument count, zero.
That base64 string is itself a packed binary record. Decode it and you get three fields laid out back to back:
byte[] blob = Convert.FromBase64String(data);
// 1) 16-byte content hash of the intercepted source file (XxHash128 in current Roslyn)
ReadOnlySpan<byte> contentHash = blob.AsSpan(0, 16);
// 2) position of the intercepted name token, as an ECMA-335 compressed unsigned integer
int offset = 16;
int position = ReadCompressedUInt(blob, ref offset);
// 3) a display name for the file, UTF-8, to the end of the blob
string displayName = Encoding.UTF8.GetString(blob, offset, blob.Length - offset);
Now the attribute means something concrete. It says: this method intercepts the call whose name token begins at character position in a file whose content hashes to contentHash, shown to humans as displayName. Glass performs exactly this decode when it meets an InterceptsLocation attribute, so the interceptor method in the type tree is tagged with the position and file it claims, instead of showing you an opaque base64 string.
From evidence to understanding
Put the two halves together and the rewrite becomes legible. Walk the type tree for methods carrying InterceptsLocation; each one is an interceptor. Its signature tells you the shape of the call it replaced — an extension-style this WeatherClient first parameter means it stands in for an instance call on WeatherClient, and the method name the generator chose (GetForecast_Fast) usually echoes the original. Then cross-reference: search the assembly for direct calls to that interceptor, and those call sites are the places the compiler redirected. The decoded position and displayName tell you which source file and roughly where, if you have the source to match the hash against.
In Glass, the interceptor methods surface with their decoded location in the IL view, and the attribute blob is expanded rather than shown raw — so you can see at a glance that a generated method is claiming a call site, which is the cue that a plain-looking call elsewhere is not what it appears to be.
When this breaks down
Be honest about the limits, because they are real.
- No source, no line number. The version 1 blob is deliberately source-relative. The content hash and character position are only resolvable if you have the original file to hash and index into. Without it you learn that a call was intercepted and its display name — never the exact visible line. This is by design: the encoding trades readability for resilience against whitespace edits.
- The call site is genuinely clean. Do not go looking for a modifier or a flag at the redirected call. There isn’t one. The redirection lives only on the interceptor, so a decompiler that doesn’t inspect custom attributes will miss the feature entirely and show a call that looks hand-written.
- The legacy form reads differently. The original preview encoding was
[InterceptsLocation(string filePath, int line, int character)]— human-readable, but brittle and now superseded. You may still meet it in older assemblies; decode it as three plain arguments, not a blob. - It is still an opt-in, moving feature. Interceptors live behind
<InterceptorsNamespaces>, and the attribute’s shape has already changed once. Treat the exact byte layout as version-dependent and read the version argument first.
Takeaway
Interceptors are the case where the honest decompile and the useful decompile diverge. The IL that executes is a direct call to a generated method, and rendering that faithfully is correct — but it hides a compile-time rewrite. The whole story is folded into one custom attribute on the interceptor, and reading it means decoding a base64 record of a content hash, a source position, and a name. Glass does that decode for you, which is the difference between seeing a call to GetForecast_Fast and understanding that your own GetForecast call was quietly replaced.
Glass.NET is a free .NET decompiler. See the product page and the docs.
Try Nebula.NET
Harden your .NET code in minutes — start with the free edition.