System.AccessViolationException Error

mscn
mscn used Ask the Experts™
on
I have a C# app that uses a web.browser controller to display an SVG graphic. The program worked fine until adding the SVG graphic to the page. Now the app freezes after rendering the SVG viewer for several seconds and I get the following error message:

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 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.RunDialog(Form form)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at System.Windows.Forms.Form.ShowDialog()
   at ALMNotifyApplication.ALMApplicationContext.mDisplayForm_Click(Object sender, EventArgs e) in C:\Users\user\Documents\Visual Studio 2010\Projects\AegisLINK Monitor - Win7\ALMNotifyApplication\ALMApplicationContext.cs:line 75
   at System.Windows.Forms.NotifyIcon.OnDoubleClick(EventArgs e)
   at System.Windows.Forms.NotifyIcon.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.NotifyIcon.WndProc(Message& msg)
   at System.Windows.Forms.NotifyIcon.NotifyIconNativeWindow.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.4959 (win7RTMGDR.050727-4900)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
AegisLINK Monitor
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/user/Documents/Visual%20Studio%202010/Projects/AegisLINK%20Monitor%20-%20Win7/ALMNotifyApplication/bin/x86/Debug/AegisLINK%20Monitor.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    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.4927 (NetFXspW7.050727-4900)
    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.4927 (NetFXspW7.050727-4900)
    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.4927 (NetFXspW7.050727-4900)
    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.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Microsoft.mshtml
    Assembly Version: 7.0.3300.0
    Win32 Version: 7.0.3300.0
    CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.mshtml/7.0.3300.0__b03f5f7f11d50a3a/Microsoft.mshtml.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.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
What happens if you try different image file formats for the SVG graphic?

Author

Commented:
I'm not sure I understand. The SVG image uses an XML file to render a real time graph. I just tried using a static PNG and was not able to recreate the error. It seems it is something going on with rendering the SVG graphic.

Author

Commented:
I've requested that this question be deleted for the following reason:

No solutions were given. Therefore, I see no warrant to post private code on a public forum.
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Author

Commented:
I think I'll give the experts a little more time along with a request for attention.

Author

Commented:
MORE INFO: hovering or clicking on the graph will cause the graph to stop rendering and the window to freeze.
Most Valuable Expert 2012
Top Expert 2008

Commented:
That exception (buffer overrun protection) usually means a bug in a component outside of your control.  Finding just the right one is very difficult, and I am not guaranteeing any results.

Author

Commented:
Well the thing is that there is basically nothing in the Windows form other than the web control. Here is the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ALMNotifyApplication
{
    public partial class Details : Form
    {
        public Details()
        {
            InitializeComponent();
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }
    }
}

Open in new window

Most Valuable Expert 2012
Top Expert 2008

Commented:
The system is making a COM or Win32 call here:

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

Open in new window


What operating system is this application running on?

Author

Commented:
This is running on Windows XP and 7. I have the same error on both. Could that call be the issue?
Most Valuable Expert 2012
Top Expert 2008

Commented:
You would need to find out what component the underlying call is getting routed to, which is pretty difficult to determine.  It appears to be related to how SVG files are rendered, but there is not a way to find out (off the top of my head).

Author

Commented:
So where would I start?
Most Valuable Expert 2012
Top Expert 2008

Commented:
Let's start with how you are getting the web browser control to display SVG images?

Author

Commented:
I am using an <object> tag with type svg/xml. The SVG is rendered by Adobe SVG Viewer, which is no longer officially supported of course.
Most Valuable Expert 2012
Top Expert 2008

Commented:
The Adobe SVG viewer would be a good candidate for a misbehaving code base.  What version are you using?

Author

Commented:
I was originally using version 6 preview 1 which is a beta released in 2003. I just uninstalled and tried version 3.3 released in 04/2005. (I don't understand the version numbers either...) Both produced the same results.
Most Valuable Expert 2012
Top Expert 2008

Commented:
What version(s) of Internet Explorer do you have installed?

Author

Commented:
I had v8 installed. I uninstalled v8 and am installing v9 as we speak.
Most Valuable Expert 2012
Top Expert 2008

Commented:
I believe that IE 9 is supposed to have SVG support (it looks like it was the first version of IE that supported SVG without a plug-in).

Author

Commented:
I installed IE 9 and was able to get the graph to display without a plugin and without error; however, this is hardly a solution as I am realizing that IE9 is not compatible XP. XP is my target audience.
Most Valuable Expert 2012
Top Expert 2008

Commented:
I think that Adobe dropped support for the SVG viewer plugin, because most browsers (except for IE) support the SVG format natively.  I believe that you are kind of stuck in a weird zone, where you need to find another solution.  You might be able to use Internet Explorer automation.  To be certain, I would need to know the environment that this application will operate in.

Author

Commented:
I've looked at webkitdotnet and the firefox equivalent but they don't natively support SVG it seems. Are there any other options? What do you mean by environment?
Most Valuable Expert 2012
Top Expert 2008

Commented:
Environment = operating systems, running on a network (or locally), application type (WinForms, WPF), framework version, etc.

Internet Explorer automation:

InternetExplorer Object
http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx

Controls an instance of Windows Internet Explorer through automation.

sing System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class EventHandlers
    {
        public void OnBeforeNavigate2(object sender, ref object URL, 
                                      ref object Flags, ref object Target, 
                                      ref object PostData, ref object Headers, 
                                      ref bool Cancel) 
        {
            Console.WriteLine("BeforeNavigate2 fired!");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            EventHandlers e = new EventHandlers();
            SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
            object Empty = 0;
            object URL = "http://www.live.com";

            // override BeforeNavigate2 event
            IE.BeforeNavigate2 += new
                 SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(
                         e.OnBeforeNavigate2);

            IE.Visible = true;
            IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);

            System.Threading.Thread.Sleep(5000);

            IE.Quit();
        }
    }
} 

Open in new window

Commented:
I got stepped around the problem by placing a clear DIV over the SVG image so that clicks and mouseovers would be registered to the DIV instead of the SVG image. This worked.

Author

Commented:
Thanks for the help, guys!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial