I had to reply to this because I had the same error and did not come across a solution until I took some steps....
Running Windows 7 with Office 2007 and VS 2010.
I was cruising right along developing some code-behind for various InfoPath forms and then one day I could no longer open the code behind.
I could right-click and enter Design mode - no issue. But clicking the menus to open the code-behind resulted in the above error.
Clicking the various buttons (which had the code behind and would normally open VSTA) resulted in the above error.
I checked and dug in group policy (I was aware of the CustomCode = Disallow).
I ran procmon and started checking the "missing" registry keys.
I checked event logs, error logs, and anything else I could get my hands on - nothing helped.
Finally I was able to fix the form AND replicate how I fixed it.
-
Open the form...
-
Publish the form...
-
Cancel publishing when you chose where to deploy the form...
Now you'll be able to edit the code behind.
I have replicated this over and over so I'm not sure what Publishing does to "reconnect" the code-behind that simply opening the code-behind doesn't - but here is a possible solution for the above error