1

I wrote a small app that I've distributed to several coworkers. It works great most of the time. But users occasionally see the following exception. From talking to them, it seems to happen the first time they run it and never again.

System.ObjectDisposedException: Cannot access a disposed object. 
Object name: 'SplitContainer'. 
   at System.Windows.Forms.Control.CreateHandle() 
   at System.Windows.Forms.Control.get_Handle() 
   at System.Windows.Forms.ContainerControl.FocusActiveControlInternal() 
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value) 
   at System.Windows.Forms.Control.set_Visible(Boolean value) 
   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.Run(Form mainForm) 
   at WindowsFormsApplication1.Program.Main() in C:\Users\chris\Documents\Visual Studio 2015\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 23) 

I cannot reproduce it at will. Except for the designer code, I've added try/catch blocks around every piece of my code that references the SplitContainer, and as you can see, I even started distributing the .PDB file hoping to get more details, but Program.cs:line 23 is just 'Application.Run(new Form1())'

A piece of info that is probably relevant is that I am storing the SplitterPosition of the single SplitContainer control in the Application.Settings so as to be able to restore where the user last had the splitter. Given that it seems to happen once and never again, it's likely related to that but again, I've added 'if (splitContainer1.isDisposed)' checks before every reference and even wrapped those in try/catch blocks but it's still happening.

I'm wondering if this is happening in the Designer code, but if that's the case, I'm not sure how to correct it.

Does anyone have any tips for how I might track down this issue?

Thanks in advance, Chris

PS - I'm fairly inexperienced here at StackOverflow, so please forgive me if I've left out important details. I'll be happy to share whatever is needed. I really appreciate the help!

Chris S
  • 11
  • 2
  • Running any code in the form's load event? – LarsTech Mar 01 '17 at 22:15
  • Yes, calling several small functions: 1. Upgrade app settings from previous versions 2. Recall window state (minimized/maximized/etc) from settings 3. Read the ClickOnce app version and add it to the title bar 4. Check for the presence of an IE-related reg key (I'm using a WebBrowser control) 5. Show a Help form on the first run. – Chris S Mar 01 '17 at 22:30
  • Try removing or renaming all your program's registry settings to test your "first run" scenario. Since it only happens on your client's first runs, you might be assuming certain values are there when they aren't. – LarsTech Mar 01 '17 at 22:41

0 Answers0