For what it's worth I've struggled with this issue on my R3 mega 2560 for about a day earlier in the week. My problems was using the RX0 ( digital pin 0 on the board ) as part of my circuit when other pins could have easily been used. This was ( I believe ) interfering with the serial communication w/ the host that occurs during programming. I've since moved the function I had tied to that pin to another output and have had no issues since.
It may seem obvious but it wasn't at the time Hope this helps.
thanks