When Resharper isn’t so sharp
June 6th, 2008
One of the things I wanted to add to MceFM was to let users tell Last.fm to Love/Ban songs.
I was using the RegisterRawInputDevices Windows call to listen for events generated by the remote control. This takes a RAWINPUTDEVICE structure as a parameter:
[StructLayout(LayoutKind.Sequential)] internal struct RAWINPUTHEADER { [MarshalAs(UnmanagedType.U4)] public int dwType; [MarshalAs(UnmanagedType.U4)] public int dwSize; public IntPtr hDevice; [MarshalAs(UnmanagedType.U4)] public int wParam; }
My code was working fine, and then suddenly stopped working. I lost at least an hour tracking back what I’d changed recently, and then finally realized that I’d run Resharper’s Reformat Code tool:
Notice that last item? This is what it did to the structure:
[StructLayout(LayoutKind.Sequential)] internal struct RAWINPUTHEADER { [MarshalAs(UnmanagedType.U4)] public int dwSize; [MarshalAs(UnmanagedType.U4)] public int dwType; public IntPtr hDevice; [MarshalAs(UnmanagedType.U4)] public int wParam; }
The RegisterRawInputDevices call was falling over because the structure was totally out of whack. I’m still a big fan of Resharper — and this is marked as fixed in the next release.


Leave a Reply