Just recently I had the fun to waste hours and hours debugging one of the most annoying problems in my Tracky project I have encountered so far in C#.

I have a TabControl with several Tabs (TabPages). One of these is used as a search result tab. In that tab, I have a panel as "parent" container for all search results. A search result is an own defined Control. Since I have to consider previous searches, I have to empty this panel before displaying the new results, apparently. Due to the logic of Tracky I also (have to) keep the Controls (references) for the occasionally later reuse in another context of one or more of these. Hence I just intend to Clear() the parent panel control, making it empty for the new search results instead of Dispose() of every control in there.

According to MSDN the Clear() function:

removes all controls from the collection

Meaning: it only removes them but doesn't necessarily destroys them. As you may know, the GarbageCollector of C# runs every now and then to fetch all things that aren't used anymore or in other words don't have a reference lying around in the program anymore. Due to a Copy&Paste accident I ended up clearing the TabPage instead of the parent panel container holding potential search results.

Now, with the above-mentioned description and logic you could think, the panel will not just be removed but destroyed. Tracky has no (visible) reference to the (public) panel, it is "just there" and accessed through its name directly. The fun thing now is, when adding new Controls to this panel, C# will stay silent. There will be no errors or exceptions thrown despite a try/catch block and you will be confused why the hell the search results aren't displayed. Since the results are user defined controls you search there and everywhere else for the error but not whether or not the panel is actually still there. (My) Logic says it's destroyed but it seems that's not the case. You can't bring it back either, since there's no reference that could be used to do so.

//instead of mainForm.panelSearchResults.Controls.Clear()
mainForm.tabSearchResults.Controls.Clear();

try {
  // own defined control for search results
  MyUserControl ctrl = new MyUserControl();
  // adding the control to the previously removed panel
  mainForm.panelSearchResults.Add(ctrl);
} catch (Exception e) {
  // won't be executed
  Debug.WriteLine(e.Message);
}  

Since Control.Add has no return value there's no possibility to check whether the addition worked or not. Seems like you're able to add controls to with Clear() removed controls in C# as long as they existed at some point. There's probably some logic behind the scenes explaining this but I can't think of any reasonable logic.

grinning face
face with tears of joy
exploding head
clapping hands
partying face
thumbs up
sleeping face
pile of poo