I have a couple of .NET classes that I use to call stored procedures in two lines of code using .NET reflection.  One of my methods creates a SqlCommand for a stored procedure by examining attributes and parameters on the method that called it (IE the call to the stored proc basically needs to match the method signature).  This technique was initially posted here back in 2002! It was working beautifully for me in debug mode, but suddenly stopped working in release builds. Why?  Because of a JIT optimization known as inlining.  Basically, the .NET JIT compiler took my simple function’s code and placed it “inline” where the call to that function occurs.  I discovered this after a good bit of pain, and finally, a manual in-code reflection-based stack dump to a log file… my method was no where to be found in …

GetCustomAttribute returns null or nothing in release builds Read more »