Question

I have some code that relied on methods not being inlined :

internal class MyClass : BaseClass
{
    // should not be inlined
    public void DoSomething(int id)
    {
       base.Execute(id);
    }
}

public abstract class BaseClass : MarshallByRefObject
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    protected void Execute(params object[] args)
    {
         // does a stack walk to find signature of calling method
    }
}

Of course this does only work if the DoSomething method is not inlined. This is the reason why the base class derives from MarshallByRefObject, which prevent inlining of public methods.

It worked until now, but I got a stacktrace from a .Net 4 server showing that the stackwalk reached the caller of DoSomething.

Is the .Net 4 inlining more clever and detect that MyClass is internal and has no chance of being substituted with a proxy ?

Was it helpful?

Solution

The commenter here suggests that you also need to specify NoOptimisation to achieve what you want.

http://connect.microsoft.com/VisualStudio/feedback/details/162364/methodimpl-methodimploptions-noinlining-doesnt-work-correctly-on-x64

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top