Check your INI file encoding
Last week I was assisting a customer with a production problem that appeared to be caused by the CLR JIT compiler inlining certain properties and methods. One of the quick workarounds we tried was to temporarily turn off JIT optimizations to see if it was indeed the inlining causing the problem. We did this using the .NET Framework Debugging Control INI file.
I got out Visual Studio, created a new text file, called it the same name as our EXE, but with an INI extension, and added the following to the file:
[.NET Framework Debugging Control] GenerateTrackingInfo=1 AllowOptimize=0
Then I saved the file and copied it to the same directory as our EXE, and restarted the application. The strange thing was that it had no effect whatsoever! Still our problem was there, and we were convinced by this point that it was the JIT inlining. I even went to the lengths of putting together a quick sample application that reproduced our problem and still this INI file wasn’t working. After over an hour banging our heads on our collective desks I started getting paranoid about the precise text in the INI file, and that’s when it dawned on me. The default encoding of text files in Visual Studio is UTF-8 with a signature. A quick check of the advanced save options confirmed this:

Flipping this over to Windows codepage 1252 and resaving the file solved the problem. No more JIT optimizations and our problem disappears, finally confirming our suspicions. So it would seem that GetPrivateProfileString doesn’t like Unicode byte order mark signatures!