"Attempted to read and write protected memory. This is often an indication that other memory is corrupt" error when implementing ItemCheckingOut event handler in MOSS 2007/WSS 3

If you ever tried implementing ItemCheckingOut event handler wanting to prevent end users from checking out documents if certain business rules doesn’t meet, you typically would implement the “ErrorMessage” & “Cancel” properties of SPItemEventProperties. However, when you do this, you might have seen the below error: “Attempted to read and write protected memory.  This is…

3