Using VisOcx DrawingControl:SRC Property works with Visio2003 NOT with Visio2007

Started by RealCosmo, September 03, 2010, 02:06:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RealCosmo

Hi guys,

i got serious problems in my implemented application. In the past we used Visio 2003 now we switched to Visio 2007 and out of nowhere the following code does not work anymore. The code is quite long so i try to show the relevant code lines for the problem:

// The drawing control
AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl m_cVisVisio;

// The visio application
Visio.Application m_cVisApp;

// We draw the Visio file automatically by the program out of a configuration text file
// Doing this, to be faster, we do this in the "background" by using OpenEx and Close
Document visioDocPlant = m_cVisApp.Documents.OpenEx(sFile, (short)(VisOpenSaveArgs.visOpenDontList));

....
// During drawing we do various things, e.g. placing the shapes, arranging them and assembling/grouping them
// therefore sometimes we have to select a shape in a group
Selection selGroup = m_cVisioApp.ActiveWindow.Selection;
selGroup.Select(sShape, (short)VisSelectArgs.visSelect);

....

// At the end we save and close the document/file
visioDocPlant.SaveAs(sFile);
visioDocPlant.Close();

....

// Later in the program we want to show the visio file in the ActiveX Control
// By doing this we use the Src Property
m_cVisVisio.Src = sFile;

This worked fine with Visio 2003, but when using Visio 2007 now, when setting the Src Property i get the following error:
System.Runtime.InteropServices.COMException (0x86DB09C6): Exception from HRESULT: 0x86DB09C6
   at Microsoft.Office.Interop.VisOcx.DrawingControlClass.set_Src(String pVal)
   at AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl.set_Src(String value)

The result of this error is, that the file is not shown in the Visio Control, despite that the file is completely there on the harddisk. When i close my complete application and reopen, it's all there.

And the really weird thing is i only get the error, when i do the group selecting (the Select(...) function from above).
When i comment that out, everything works fine. I really have no clue anymore.

I already built everything with the 11.0 AND the 12.0 libraries, both show the same problem.

aledlund

As I've been moving my stuff forward I've observed that Visio is now testing operations more vigorously and things that used to appear to be working had actually been failing silently. For things like your selection logic I have had to wrap them in try-catch-endtry and then test that they really returned what I was looking for.
Al

Nikolay

Googling your error code (0x86DB09C6) gives the following:

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/ac3d2fa2-8226-4764-8cc7-08168929766f

According to that topic, this might be a file format problem.
E.g. you might have your initial "background" in "old" (visio 2003?) format; try saving it in "current" (visio 2007) format instead.
Just shooting in the dark of course... :)

RealCosmo

First of all thanks for your replies.

The format hint is a good one as we start with a prepared Template file (which was saved in 2003). Unfortunately first saving it in 2007 didn't solve the problem either.
But i'll keep looking what else format problems could arise.

I debugged the problem some more times and now (we already had a try-and-catch around the statement) got sometimes the following error message instead of the COMException:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Microsoft.Office.Interop.VisOcx.DrawingControlClass.set_Src(String pVal)
   at AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl.set_Src(String value)

Seems like the previous Close doesn't close (or free) the file or what??
Still clueless.... HELP!

aledlund

Since the file is out on the drive, some additional thoughts. Is the file local or on a server (goes to system timings)? Before you attempt to load the file into the drawing control, do you wrap the file read in a fileexists wrapper (once again goes to system timings)? Your code example shows the document closed instruction, it doesn't show a "visDocPlant = nothing", or a garbage collect.
Just ramblings from an old guy,
al

RealCosmo

Thx for your ideas, but already tried all that timing stuff (even inserting some sleeps and so on) and garbage collecting. Didn't help.

A very weird behavior is, when the first assignment to the Src Property fails, a second one (e.g. in the catch statement of the thrown exception) works.
But still the ActiveX Control is somehow "damaged" as doing another assignment later in the program the whole program crashes with:

Source: System.Windows.Forms
StackTrace:    at System.Windows.Forms.UnsafeNativeMethods.ThemingScope.DeactivateActCtx(Int32 dwFlags, IntPtr lpCookie)
   at System.Windows.Forms.UnsafeNativeMethods.ThemingScope.Deactivate(IntPtr userCookie)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at DpsGUI.Program.Main(String[] args)
TargetSite: Boolean DeactivateActCtx(Int32, IntPtr)

The only workaround that helps is completely closing the application and restarting it.  :'(

Microsoft sucks! How can they alter the functionality behind COM-Interfaces in such a way that code developed with previous versions always crashes!!!


RealCosmo

Solved it:
We used the "wrong" access to the selection.

Instead of
Selection selGroup = m_cVisioApp.ActiveWindow.Selection;
we use now
Selection selGroup = sShape.CreateSelection(VisSelectionTypes.visSelTypeEmpty, VisSelectMode.visSelModeOnlySuper, null);

As we drew the file in the "background" using the first Selection statement it chose a selection from the active shown file (which was not the one we operated on).
Somehow Visio 2003 didn't have any problems with that (which it should, because this was really a bug), but Visio 2007 did ...