为什么openfiledialog在第二次选择文件后显示'Path does not exist'或'Catastrophic Error'?

Why does openfiledialog say 'Path does not exist' or 'Catastrophic Error' after selecting a file for the second time?

我正在尝试制作一个文件显示。当用户 select 一个文件时,它会在 window 中显示该文件的图标。当我 select Google Chrome 图标并单击 openfiledialog 中的 'OK' 时,会出现预期的结果。 (见下图)

但是,当我 select 另一个图标(例如 Word)时,它给我错误 'Path does not exist'。 (见下图)

如果我 select 另一个文件(例如文件资源管理器),它会给我 'Catastrophic Error'(见下图)

出于某种原因,此问题仅发生在快捷方式文件上。对于.txt 文件或.exe 文件等其他文件,不会出现此问题。

这是我的代码(Add_Item 是按钮的名称)

private void AddItem_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                foreach (String myfile in openFileDialog.FileNames)
                {
                    // here myfile represent your selected file name

                    //get filename
                    string filename = System.IO.Path.GetFileName(myfile);

                    //TODO: Create settings


                    Icon icon1 =  System.Drawing.Icon.ExtractAssociatedIcon(myfile);
                    Bitmap icon = icon1.ToBitmap();

                    System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                    image.Source = BitmapToImageSource(icon);

                    Tiles.Children.Add(image);



                }
            }
        }

谁能帮帮我?

谢谢

好的,{DeferenceLinks = false} 解决了我的问题。