[Solved] AccessViolationException when calling Close

Feb 1, 2010 at 10:41 PM

I´m getting an AccessViolationException when using Close() to exit the application.

System.AccessViolationException was unhandled
       em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       em _01_AddingRibbonSupport.Program.Main() em D:\Visual Studio 2008\Projects\FlashUnits\FlashUnits\Program.cs:line 19
       em System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       em System.Threading.ThreadHelper.ThreadStart()

Feb 10, 2010 at 9:10 PM

Are you, by any chance, calling Close() from a handler to one of the ribbon buttons?

calling Close() raises the form_closed event, which then calls ribbon.DestroyFramework()
But you are still using it! (you are still in the ribbon handler, somewhere up in the stack)
So this cause the exception.

Either don't call close firectly from the handler (you can invoke a timer that will close the form).
or, don't call DestoryFramework on form_closed (maybe in another location, or not at all, process should clean up after itself..)



Feb 11, 2010 at 9:52 AM
It's not elegant, but the timer does work. Thanks.
Apr 23, 2010 at 8:54 AM

Check this post for an alternative solution:

Crash while closing application that uses Windows Ribbon Framework

Apr 23, 2010 at 5:25 PM

Nice work :)

Jun 10, 2010 at 2:40 PM

I have the same problem and the above link says "account suspended". Could anyone post the alternative solution?


Jun 10, 2010 at 5:20 PM



Jun 10, 2010 at 6:09 PM

I get the same "This account has been suspended" thing when I click on that link.

Jun 13, 2010 at 11:35 AM

This is the same, posted on codeproject.



Jun 13, 2010 at 9:55 PM

Thank you. The other links work now too. :)