Cracker
Cracker

Reputation: 912

Visio drawing control AccessViolationException on adding a shape

I have a form with a Visio Drawing Control placed on it. I am using Visio Drawing Control 11.0 (Visio 2003 is installed on my PC). On the form load event, I do the following:

private void Form1_Load(object sender, EventArgs e)
{
    this.axDrawingControl1.Src = @"D:\visio test\drawing.vsd";
    Document currentStencil = this.axDrawingControl1.Document.Application.Documents.OpenEx(@"Basic_U.vss", (short)VisOpenSaveArgs.visOpenDocked);
    Window stencilWindow = this.axDrawingControl1.Document.OpenStencilWindow();
}

When I run the application, I add a shape to the document and then the application crashes with the AccessViolationException. The error message says Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
However, when I do NOT open a document by setting the DrawingControl.Src property to document's filename, the application works fine, but I need to open a document and edit it using the drawing control.

Is there a way to fix this?

Upvotes: 1

Views: 622

Answers (1)

klugerama
klugerama

Reputation: 3352

You likely need to wait until the document is fully loaded.

Add an event handler for this.axDrawingControl1.DocumentOpened and move your drawing code to that handler.

Upvotes: 1

Related Questions