runtime: Incorrect parameters passed when profiler set COR_PRF_DISABLE_INLINING

When profiler SetEventMask with COR_PRF_DISABLE_INLINING flag set (disable inlining), method get incorrect arguments (on Linux and MacOs, it works correct on Windows). Try to use next application (compile with release from console app template):

using System;

namespace repro
{
    public class SomeClass
    {
        public string SomeMethod(string s1, string s2,
            string s3, string s4, string s5, string s6)
        {
            Console.WriteLine($"{s1}:{s2}:{s3}:{s4}:{s5}:{s6}");
            return s1;
        }
    }

    public struct Struct
    {
        public object o1;
        public object o2;
    }

    public static class BadClass
    {
        //[MethodImpl(MethodImplOptions.NoInlining)]
        public static string BadInline(string s1,
            string s2, Struct @struct, string s3, string s4,
            string s5, string s6)
        {
                var mapperExpression = new SomeClass().SomeMethod(s1, s2,
                    s3, s4, s5, s6);
                return mapperExpression;
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            BadClass.BadInline(
                "s1",
                "s2",
                new Struct(), 
                "s3",
                "s4",
                "s5",
                "s6");
        }
    }
}

Expected console output: s1:s2:s3:s4:s5:s6 Broken console output: s1:s2:s3:s4:s6:s6

If BadInline method marked with MethodImplOptions.NoInlining issue is not reproducible. Issue is only reproducible when profiler that set COR_PRF_DISABLE_INLINING is loaded. I’ve reproduced it on version 2.2.5 and only with test application release build.

If it is required, I may create test sample with profiler included (thought it will take some time).

Automapper 8.0 use pattern affected by this issue, so some of applications that use Automapper will crash if loaded with profiler requested COR_PRF_DISABLE_INLINING.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Most of users of Automapper, who use profiler that set COR_PRF_DISABLE_INLINING will be affected. Issue occurs inside AutoMapper.Mapper.Initialize (can’t be avoid to use Automapper) if user have at least one Nullable<T> in source class.

I also reproduced the issue on 2.1, which wary me even more, as 2.1 is LTS and will be supported even longer than 2.2. Can fix be also ported to 2.1?