The MSDN documentation says that

"You can call the GetFolderPath() method only while the dialog box is being displayed. After the dialog box has been closed, this function will no longer work, and the method will fail with an assertion."

Since you are closing the File Open dialog, that is the reason you get this assertion. The code for GetFolderPath() checks this line ASSERT(::IsWindow(m_hWnd)). As m_hWnd is NULL in this case, the error occurs.

Hope this helps.