{"action":"opened","issue":{"url":"https://api.github.com/repos/MahApps/MahApps.Metro/issues/2476","repository_url":"https://api.github.com/repos/MahApps/MahApps.Metro","labels_url":"https://api.github.com/repos/MahApps/MahApps.Metro/issues/2476/labels{/name}","comments_url":"https://api.github.com/repos/MahApps/MahApps.Metro/issues/2476/comments","events_url":"https://api.github.com/repos/MahApps/MahApps.Metro/issues/2476/events","html_url":"https://github.com/MahApps/MahApps.Metro/issues/2476","id":149392984,"number":2476,"title":"MetroWindow OnClosing exception (.Net 4.0)","user":{"login":"gigios","id":8749627,"avatar_url":"https://avatars.githubusercontent.com/u/8749627?v=3","gravatar_id":"","url":"https://api.github.com/users/gigios","html_url":"https://github.com/gigios","followers_url":"https://api.github.com/users/gigios/followers","following_url":"https://api.github.com/users/gigios/following{/other_user}","gists_url":"https://api.github.com/users/gigios/gists{/gist_id}","starred_url":"https://api.github.com/users/gigios/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gigios/subscriptions","organizations_url":"https://api.github.com/users/gigios/orgs","repos_url":"https://api.github.com/users/gigios/repos","events_url":"https://api.github.com/users/gigios/events{/privacy}","received_events_url":"https://api.github.com/users/gigios/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-19T08:53:58Z","updated_at":"2016-04-19T08:53:58Z","closed_at":null,"body":"It is not clear why but, when I close the main window of my application, I receive an exception because the variable metroActiveDialogContainer is null.\r\nI have checked my code and for each MetroWindow loaded I have the same OnClosing event, but when it is closed the last window I receive an additional OnClosing event where the metroActiveDialogContainer is null.\r\n\r\nI have applied this fix (MetroWindow.cs line 782):\r\n\r\n`var dialog = this.Invoke(() => this.metroActiveDialogContainer?.Children.OfType<BaseMetroDialog>().LastOrDefault());`\r\n\r\nI have only added a Null-conditional operator (“?.”)\r\n\r\nProbably the problem is on my side (I think that there is an hidden window that is loaded and not closed in my code) but I think that this fix can be inserted in the 'official' code."}}