Visio VSTO add-in errors on Redo but seems to work fine otherwise

Started by Visisthebest, August 19, 2021, 10:34:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

In a Visio VSTO add-in, I have a weird situation that the code executes properly when the user executes the action via the context menu on a shape, but if you Undo then Redo some actions but not all give this error:

Exception thrown: 'System.Runtime.InteropServices.COMException' in ExtendedVisioAddin1.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll

Nothing happens though the software if fine and the diagram is correct.

I use the QUEUEMARKER in the context menu in this manner in the action section:

QUEUEMARKEREVENT("AddWorkFlowShape,"&ID())

I get the ID of the shape that is calling the code in the add-in via the QUEUEMARKEREVENT from the ContextString this way, this prevent a situation where a ReDo is executed while another shape is selected (which I fear could cause issues).

Although the errors (only when doing a Redo) do not get in the way of my add-in working properly, I would very much like to understand why I get these errors at all even though my code normally executes without errors.

Thank you for sharing your Visio insights!
Visio 2021 Professional

Visisthebest

I also notice that for some actions of adding a shape (including adding a connector), run from a shape's context menu in the manner above, some user actions on Redo cause the same shape to be added twice(!) even though the original action just adds the shape once.

This probably has to do with the error I get above, hopefully a useful clue.
Visio 2021 Professional

Visisthebest

As you can see in the Undo redo menu screenshots attached, I undo one user action, but after redo I suddenly have Undo Items (A user action and a drop) and two shapes instead of just one shape.

Whether I set an undo scope does not matter for the above, same issue.

If I get the Visio shape from the selection rather that get the ID from the contextstring as per the above, also does not matter I get two shapes.

Normally everything goes fine, but after undo upon redo I get this behavior.
Visio 2021 Professional

Visisthebest

Now for the weird part, the shape doubling issues only happens when Autosize Page is on (I drop the shapes first randomly at the 0,0 position, then lay them out, which causes the corner of the page to expand on every drop when Page AutoSize in on).

For some shapes I still get this error though:

Exception thrown: 'System.Runtime.InteropServices.COMException' in ExtendedVisioAddin1.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll

So the shape doubling issue may or may not be unrelated.
Visio 2021 Professional

Visisthebest

To further isolate the issue, the problematic Redo behavior only happens with shape context menu user actions and queuemarker events, if I execute the same actions with a button on the ribbon, Undo/Redo also performs flawlessly.
Visio 2021 Professional