Hi all
Sometimes, but not always, I'm finding that the Layer.Add, Cell.GlueTo and Window.Select methods throw errors similar to:
Specified cast is not valid at System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object objSrc, IntPtr itfMT, IntPtr classMT, Int32 flags) at Microsoft.Office.Interop.Visio.IVLayer.Add(Shape SheetObject, Int16 fPresMems)
I'm using VB2010, Visio 2007 and currently testing on Windows XP 32 bit. The program is a stand-alone .exe program using Visio via .NET interop. The same program, with the same data can run several times without problem and then once this error has been thrown, the same error will be thrown every time until the Visio file is closed and re-opened.
This VB2010 code was derived from a VB6 program which has been working fine for 2,000+ users over a period of about 15 years.
Unfortunately I've not been able to replicate these problems in a small test program which is making the debugging process rather tedious and it's another aspect of this problem which is worrying and confusing me.
The program is adding a 100 or so shapes from a stencil and gluing lines between them. I've tried playing with the settings of such properties as DeferRecalc, EventsEnabled, InhibitSelectChange, LiveDynamics, ShowChanges and UndoEnabled as I thought Visio might be having a problem updating the screen or allocating memory to the undo manager or something. I've also tried Application.DoEvents.
I've re-written some of my code to avoid using Window.Select which I was using to select shapes to create groups. I guess I could also re-write the code to avoid using GlueTo, but I don't think I can always avoid using Layer.Add.
Any thoughts or comments would be much appreciated.
Best regards
Roger Billsdon