Question

The problem appears to be related to the Expando object being passed in to the methods. If I pass in an ExpandoObject the Compiler Services Information that should be automatically generated is blank. If you don't use an ExpandoObject in the method the information is passed in just fine.

I created a quick test case:

public class TestClass
    {
        public void TestWithClass(object SomeClass, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
        {
            Console.WriteLine(memberName); // Compiler Services information prints out just fine.
        }

        public void TestWithExpando(ExpandoObject xPando, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
        {
            Console.WriteLine(memberName); // Compiler Services information is blank
        }

        public void RunTest()
        {
            //This test case works fine.
            var jnk = new Junk {Test = "TEST DATA"};
            TestWithClass(jnk);


            //This test case fails to print the Compiler Services information.
            dynamic xp = new ExpandoObject();
            xp.Test = "TEST DATA";

            TestWithExpando(xp);
        }

        public class Junk
        {
            public string Test { get; set; }
        }
    }
Was it helpful?

Solution

Compiler Services Information is done by the compiler, the problem is not the ExpandoObject, it's the dynamic keyword, as you are delaying invocation, thus it's handled by the DLR not the compiler. Casting to object first will fix this.

TestWithExpando((object)xp);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top