[Solved] AccessViolationException when calling Close

Feb 1, 2010 at 11:41 PM

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

System.AccessViolationException was unhandled
  Source="System.Windows.Forms"
  StackTrace:
       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()
  InnerException:

Coordinator
Feb 10, 2010 at 10: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 10:52 AM
It's not elegant, but the timer does work. Thanks.
Coordinator
Apr 23, 2010 at 9:54 AM

Check this post for an alternative solution:

Crash while closing application that uses Windows Ribbon Framework

Apr 23, 2010 at 6:25 PM

Nice work :)

Jun 10, 2010 at 3:40 PM

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

Thanks

Coordinator
Jun 10, 2010 at 6:20 PM

http://blogs.microsoft.co.il/blogs/arik/archive/2010/04/14/crash-while-closing-application-that-uses-windows-ribbon-framework.aspx

 

Jun 10, 2010 at 7:09 PM

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

Coordinator
Jun 13, 2010 at 12:35 PM

This is the same, posted on codeproject.

http://www.codeproject.com/Articles/72501/Crash-while-closing-application-that-uses-Windows-.aspx

 

Jun 13, 2010 at 10:55 PM

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