none
System.AccessViolationException: Attempted to read or write protected memory.This is often an indication that RRS feed

  • Question

  • Hi,

    I have had the same issue exactly as posted at here : http://www.windows-tech.info/1/f10a0726381d08ff.php

    Below is exception :

    System.Reflection.TargetInvocationException: Exception has
    been thrown by the target of an invocation. ---> System.AccessViolationException
    : Attempted to read or write protected memory. This is often an indication that
    other memory is corrupt.
       at System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr pUnk, IntPtr
     itfMT, IntPtr classMT, Int32 flags)
       at System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()
       at System.Windows.Forms.WebBrowser.get_Document()
       at System.Windows.Forms.WebBrowser.get_ReadyState()
       at Ohlala.Motor.Common.ExtendedWebBrowser.webBrowser_DocumentCompleted(Object
     sender, WebBrowserDocumentCompletedEventArgs e)
       at System.Windows.Forms.WebBrowser.OnDocumentCompleted(WebBrowserDocumentComp
    letedEventArgs e)
       at System.Windows.Forms.WebBrowser.WebBrowserEvent.DocumentComplete(Object pD
    isp, Object& urlObject)
       --- End of inner exception stack trace ---
       at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Ob
    ject target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAt
    tributes, RuntimeType typeOwner)
       at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Obj
    ect target, Object[] arguments, Signature sig, MethodAttributes methodAttributes
    , RuntimeType typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
    Attr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisib
    ilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
    Attr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Uns
    afeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int
    32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 r
    eason, ApplicationContext context)

    My application was built in VS2010, .NET Framework 4.0 

    Anyone can help me?

    Thanks

    Scott

    • Moved by Helen Zhou Thursday, June 30, 2011 7:44 AM (From:Windows Forms General)
    Thursday, June 30, 2011 4:36 AM

Answers

  • Hi Scott,

    I think this issue is related to Thread Synchronization. Two Thread are using one object --"WebBrowserReadyState.Complete".

    I suggest you add Monitor and lock in the code. And after starting a thread, abort it when it is completed.

    for (int i = 0; i < workerThread.Length; i++)
                {
                    workerThread[i] = new Thread(new ThreadStart(ArchiveWebsites));
                    workerThread[i].SetApartmentState(ApartmentState.STA);
                    workerThread[i].Start();
                    workerThread[i].Abort();
                }

    More Information, you can refer to:

    http://msdn.microsoft.com/en-us/magazine/cc163929.aspx

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Thursday, July 7, 2011 7:01 AM
    Friday, July 1, 2011 8:28 AM

All replies

  • Hello Scott,

    This is more appropriate to be posted on  Common Language Runtime forum, and that is mostly caused by dereferencing wrong pointers.
    You can run your app under (native) debugger and find out more.


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 30, 2011 7:44 AM
  • Hi Scott,

    I think this issue is related to Thread Synchronization. Two Thread are using one object --"WebBrowserReadyState.Complete".

    I suggest you add Monitor and lock in the code. And after starting a thread, abort it when it is completed.

    for (int i = 0; i < workerThread.Length; i++)
                {
                    workerThread[i] = new Thread(new ThreadStart(ArchiveWebsites));
                    workerThread[i].SetApartmentState(ApartmentState.STA);
                    workerThread[i].Start();
                    workerThread[i].Abort();
                }

    More Information, you can refer to:

    http://msdn.microsoft.com/en-us/magazine/cc163929.aspx

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Thursday, July 7, 2011 7:01 AM
    Friday, July 1, 2011 8:28 AM