简体   繁体   中英

Visio Add-in Experts for Visual Studio

I was wondering if anybody had any experience with dealing with managed code add-ins specifically for Visio in a .NET project. I am messing around with one and am trying to remove hyperlinks from a Shape object. Deleting them works fine and if the user saves then all works well. The problem arises when the user does not save and is prompted by Visio, before close, that there are unsaved changes and wants to know what the user wants to do. If the user selects "Don't save" and just tries to exit, the Visio application crashes with an unhandled Win32 exception that I have traced back to an Exception code: 0xc0000005 in the Windows Event Viewer. This turns out to be an "Access Violation Error". I have found the issue to be a line of code that calls the Delete method on the Hyperlinks collection of a shape (Example below). Anybody know what is going on here? Is this a MS bug that I just can't find on the Google? Hope I have enough information for you guys here. Did not think I needed to post a bunch of code since I have found only this line of code produces the exception when Visio tries to exit after a do not save. I have found this to produce the exact error with versions 12 and 14 of the Microsoft.Office.Interop.Visio.dll.

 internal static Nullable<Boolean> DeleteFirstHyperlink(Shape shape) { if(true){ //a condition to pass shape.Hyperlinks.get_ItemU(0).Delete(); return true; } else{ return false; } } 

I think you might be deleting hyperlinks from a "before shape deleted" event handler? I this case, you should not do that. Instead, you can remember what to delete and delete it afterwards in "no events pending" / "shape deleted" event handler.. Or it may be some similar case.

Check here: https://msdn.microsoft.com/en-us/library/office/ff767512.aspx

After Visio has fired the MustFlushScopeBeginning event, client programs should not call Visio methods that have side effects until the MustFlushScopeEnded event is received. A client can perform arbitrary queries of Visio objects when Visio is between the MustFlushScopeBeginning event and MustFlushScopeEnded event, but operations that cause side effects may fail.

If this is not the case, then probably one would need a complete example illustrating the problem (full source code illustrating the problem) to figure out what is going on.

I mean, normally you can delete hyperlinks without any issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM