Preventing Inlining for Code that Inspects the Stack Frames

There’s a first time for everything. Today, I got to use the attribute that prevents a method from being inlined.

There’s a good post, including a bit of a warning, on the MSDN forums regarding the issue and solution.

In my case, I was looking at the call stack to get the current method, so that I could pull some metadata attributes off of the method. Worked well until it hit the build server. Then the unit tests started failing. Adding the [MethodImpl(MethodImplOptions.NoInlining)] attribute did the trick.

If you’re going to try this, I’d recommend the article, since it discusses some potential issues with this approach.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at

Up ↑

%d bloggers like this: