I am trying to access all of the variables in a part variable table so I can export the name/value pairs to a csv file. I have everything sorted except for an error which occurs on the second pass through the for-each loop. The test count returns a value of 4 which is a little confusing as there are only two variables defined in a new part (created from template - no geometry), PhysicalProperties_Density and PhysicalProperties_Accuracy. One thing I noticed is that if I add some geometry and some dimensions to the part file, the variable table shows these but the count remains at 4. If I add a user variable to the parts variable table the count increases to 5.
Anyway the output to the immediate window (assuming a blank part is used) is:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
And the code (stripped down to only show the basics of the problem) is: