I'm suddenly getting the error "Exception has been thrown by the target of an invocation" on statements that have always worked. Same problem happens on QTP 9.0 and 9.2. I've tried rebooting and running QTP's .bat files to re-register dlls. Same problem keeps happening. For example, this statement throws the error on attempt to count any tables in my AUT.
I have seen this issue when performing a couple of SwfTable methods (.RowCount, .SetCellData) on a .NET 2.0 DataGridView object. From what I recall, the offending statement would work fine and randomly fail with the error you mention.
I believe this to ultimately be a QTP .NET add-in defect.
After a ridiculous amount of troubleshooting, including attempts to enlist the help of (then) Mercury support, I found a workaround myself...
I don't understand why this works, but I found that by referring to the SwfTable object in the offending line of code NOT by the object repository name, but instead a QTP "descriptive programming" value, the error did not occur.
Descriptive programming does not appear to help in my case.
Interestingly enough, I discovered the developer disabled the data grid's (swfTable object) "rows" property. My statements worked fine prior to that change and no longer work after it. I'm assuming it is more than a coincidence and thus I'm off to find the workaround. ...the story of my life! Thanks for the suggestion though.