The CLR has been unable to transition from COM context […] for 60 seconds

前端 未结 6 1116
栀梦
栀梦 2020-12-14 00:30

I am getting this error on code that used to work. I have not changed the code.

Here is the full error:

The CLR has been unable to transition

6条回答
  •  半阙折子戏
    2020-12-14 01:06

    Figured it out - it automatically brings you to the last location you looked in every time the dialog opens. If that location is a network location that no longer exists (ex. the other computer is off), it will just hang forever.

    My workaround looks like this:

    string initialDirectory = ...; //Figure out an initial directory from somewhere
    openFileDialog1.InitialDirectory = !Directory.Exists(initialDirectory)
                                           ? Path.GetPathRoot(Environment.SystemDirectory)
                                           : initialDirectory;
    

提交回复
热议问题