Author Topic: AccessViolation while setting src property  (Read 20803 times)

0 Members and 1 Guest are viewing this topic.

borisu

  • Jr. Member
  • **
  • Posts: 13
AccessViolation while setting src property
« on: December 28, 2008, 03:50:06 AM »
I am using Visio OCX (SDK 2007) control in C# application. While trying to load document and putting src property in .NET C# application I get AccessViolation exception.

The code is as simple as this. It is being executed in "open" button handler routine.

visioControl.Src = @"C:\Documents and Settings\Borisu\Desktop\Drawing1.vsd";

I've googled it but didn't come to any conclusion.

Please help.



See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
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)
   at callfloweditor.MainForm.visioOpen() in C:\SOLUTIONS\altalena\callfloweditor\MainForm.cs:line 135
   at callfloweditor.MainForm.openToolStripButton_Click(Object sender, EventArgs e) in C:\SOLUTIONS\altalena\callfloweditor\MainForm.cs:line 86
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
callfloweditor
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/SOLUTIONS/altalena/callfloweditor/bin/Debug/callfloweditor.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Microsoft.Office.Interop.Visio
    Assembly Version: 12.0.0.0
    Win32 Version: 12.0.4518.1014
    CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.Office.Interop.Visio/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Visio.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
AxInterop.Microsoft.Office.Interop.VisOcx
    Assembly Version: 12.0.0.0
    Win32 Version: 12.0.0.0
    CodeBase: file:///C:/SOLUTIONS/altalena/callfloweditor/bin/Debug/AxInterop.Microsoft.Office.Interop.VisOcx.DLL
----------------------------------------
Microsoft.Office.Interop.VisOcx
    Assembly Version: 12.0.0.0
    Win32 Version: 12.0.4518.1014
    CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.Office.Interop.VisOcx/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.VisOcx.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3080
    • Paul Herber's website
Re: AccessViolation while setting src property
« Reply #1 on: December 28, 2008, 05:00:30 AM »
What code comes before this?
How is 'visioControl' defined and created?

Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #2 on: December 28, 2008, 10:36:31 AM »
The control itself is dropped from tool box.

I am not sure which property you are interested in. SRC property is empty.


Then some custom stencil is open like this

Code
GetDocument().PaperSize = VisPaperSizes.visPaperSizeA4;

string currDirectory = System.Environment.CurrentDirectory;

Document altStencil =
 GetApplication().Documents.OpenEx(
 currDirectory + @"\Altalena.vss",
 (short)VisOpenSaveArgs.visOpenDocked);

Then user presses toolbar button and src property is changed.

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #3 on: December 28, 2008, 10:38:17 AM »
visioControl is

Code
private AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl;

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #4 on: December 28, 2008, 10:53:24 AM »
If that helps it works when form is created. But if src property is changed in toolbar handler it causes exception.

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3080
    • Paul Herber's website
Re: AccessViolation while setting src property
« Reply #5 on: December 28, 2008, 01:49:37 PM »
Ok, but where is visioControl set? You've defined it and set its .src property but is it set?
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #6 on: December 28, 2008, 03:12:48 PM »
I am not sure I am answering your question but the control is initialized in automatically generated InitializeComponents in form ctor, function like this
Code
this.visioControl.Dock = System.Windows.Forms.DockStyle.Fill;
            this.visioControl.Enabled = true;
            this.visioControl.Location = new System.Drawing.Point(0, 0);
            this.visioControl.Name = "visioControl";
            this.visioControl.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("visioControl.OcxState")));
            this.visioControl.Size = new System.Drawing.Size(785, 559);
            this.visioControl.TabIndex = 3;

I am basically trying to use it as described in this link - http://msdn.microsoft.com/en-us/library/aa168480.aspx

Is it correct that I cannot use SRC property after the form is intialized???

May be, as it appears in the link, "Dynamically destroy and reinitialize the Visio drawing control in the document. " is the way to go?
« Last Edit: December 28, 2008, 03:15:49 PM by borisu »

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3080
    • Paul Herber's website
Re: AccessViolation while setting src property
« Reply #7 on: December 29, 2008, 07:23:59 AM »
visioControl.Src = @"C:\Documents and Settings\Borisu\Desktop\Drawing1.vsd";

Try
Code
visioControl.Src = @"C:\\Documents and Settings\\Borisu\\Desktop\\Drawing1.vsd";

Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #8 on: December 29, 2008, 07:31:06 AM »
It is beyond my understanding ??? it is somehow connected to calling  EventList properties when adding advices or even referring to the class itself.

private void setAddAdvise()
        {

          EventList applicationEvents = eventApplication.EventList;
         EventList documentEvents = eventDocument.EventList;

            return;
}

It doesn't matter if add advise or not after calling the above lines, (or even initiating them to null!) the exception is thrown

WTF?


Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1725
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: AccessViolation while setting src property
« Reply #9 on: December 29, 2008, 08:57:48 AM »
I wonder if you are listening to Visio events that don't make sense when there is no drawing. When you reset Src, perhaps Visio is "empty" or null for a brief moment, or perhaps your events get whacked somehow.

When you set Src, maybe you should kill and re-build your event-listening stuff?

Just a quick guess....
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #10 on: December 29, 2008, 11:16:00 AM »
I can reproduce the same error with visio SDK Office Plan example it happens if I open the saved diagram twice (without changing anything)

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
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)
   at Microsoft.Samples.Visio.OfficePlan.CSharp.OfficePlanSampleForm.onMenuFileOpenClicked(Object sender, EventArgs e) in C:\Program Files\Microsoft Office\Office12\VisSDK\Samples\Office Plan\CSharp\frmOfficePlanSample.cs:line 1006
   at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.MenuItem.MenuItemData.Execute()
   at System.Windows.Forms.Command.Invoke()
   at System.Windows.Forms.Command.DispatchID(Int32 id)
   at System.Windows.Forms.Control.WmCommand(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
OfficePlanSample
    Assembly Version: 1.0.3285.32861
    Win32 Version: 1.0.3285.32861
    CodeBase: file:///C:/Program%20Files/Microsoft%20Office/Office12/VisSDK/Samples/Office%20Plan/CSharp/Visual%20Studio%2080/bin/debug/OfficePlanSample.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
AxInterop.Microsoft.Office.Interop.VisOcx
    Assembly Version: 12.0.0.0
    Win32 Version: 12.0.0.0
    CodeBase: file:///C:/Program%20Files/Microsoft%20Office/Office12/VisSDK/Samples/Office%20Plan/CSharp/Visual%20Studio%2080/bin/debug/AxInterop.Microsoft.Office.Interop.VisOcx.DLL
----------------------------------------
Microsoft.Office.Interop.Visio
    Assembly Version: 12.0.0.0
    Win32 Version: 12.0.4518.1014
    CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.Office.Interop.Visio/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Visio.dll
----------------------------------------
Microsoft.Office.Interop.VisOcx
    Assembly Version: 12.0.0.0
    Win32 Version: 12.0.4518.1014
    CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.Office.Interop.VisOcx/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.VisOcx.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.



Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1725
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: AccessViolation while setting src property
« Reply #11 on: December 29, 2008, 01:20:59 PM »
Can you put a Visio control on a form, then successfully set the SRC property?

Start there, then slowly add functionality. You ought to try and isolate the bug.

I know I've had weird behavior with various debug settings, that I finally just switched off, but I can't remember what they are, nor did I really understand what they were for at the time.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #12 on: December 29, 2008, 01:43:10 PM »
In one of the forums I saw that disabling "suppress JIT ..." in Tools->Options->C# Debugging may help but it doesn't. I have already isolated the problem, and posted it before. It is very weird and not very helpful. I still have to add advices at some moment in time. I do believe that is has to do something with events race condition because when do "slow" debugging it is not reproducible. Just to mention it is not only SRC property which may cause this exception but many others.

The problem is  reproducible with Visio Sample - not in my code. And I succeeded to do it with two different OS (XP SP2 .NET2 and 2003  .NET1).

I am confused by the fact that it is such a basic functionality. How can it possibly be not working?

By the way can someone advise how to disable events and reset all event/advises functionality? It may help before setting SRC property.

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1725
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: AccessViolation while setting src property
« Reply #13 on: December 29, 2008, 05:01:32 PM »
For AddAdvise events, I think you remove them, something like this:

doc_or_shape_or_page_or_app.EventList.Item( something ).Delete

I would imagine that you have event objects defined, so you should only delete the events you are listening for, not all of them.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1725
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: AccessViolation while setting src property
« Reply #14 on: December 29, 2008, 05:12:18 PM »
Ok, I just tried the SDK sample and it gives me the same problem when I try to open a new file.

The filePath is valid, and the file does exist...this is really weird!
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010