首页 > 解决方案 > 尝试覆盖文件时,VB.NET 抛出 System.IO.IOException unsupported

问题描述

我的应用程序中有此代码:

My.Computer.FileSystem.CopyFile("D:\Temp\Origin.log", "D:\Temp\Destination.log", True)

这段代码在 1 或 2 个月前一直可以正常工作。

在过去的几个月中,它无法执行,并且当目标文件存在时,它会在 mscorlib.dll“不支持”中引发“System.IO.IOException”。

我的目标框架是 4.7.2

我试图将目标框架更改为 4.6.2,以防 NET 框架的更新破坏了它,但我仍然有同样的问题。

现在我不得不暂时绕过这样的问题:

If My.Computer.FileSystem.FileExists("D:\Temp\Destination.log") Then
      My.Computer.FileSystem.DeleteFile("D:\Temp\Destination.log", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
End If
My.Computer.FileSystem.CopyFile("D:\Temp\Origin.log", "D:\Temp\Destination.log", True)

虽然上面的代码有效,但它破坏了覆盖重载的目的(4.7.2 AFAIK 仍然支持)

这也意味着我必须在我的应用程序代码中的太多地方更改它。

有谁知道为什么我的原始代码停止工作,或者更好的是,如何修复它?

编辑:异常堆栈:

System.IO.IOException
  HResult=0x80070032
  Message=The request is not supported.

  Source=mscorlib
  StackTrace:
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at Microsoft.VisualBasic.FileIO.FileSystem.CopyOrMoveFile(CopyOrMove operation, String sourceFileName, String destinationFileName, Boolean overwrite, UIOptionInternal showUI, UICancelOption onUserCancel)
   at Microsoft.VisualBasic.MyServices.FileSystemProxy.CopyFile(String sourceFileName, String destinationFileName, Boolean overwrite)
   at KT_Scan_Docs_Manager.Frm_Main.CreateFilelist(Int32 Meleti) in C:\Users\GTsag\Dropbox\Visual Studio\KT2-14 Scan Docs Manager\KT2-14 Scan Docs Manager\frm_Main.vb:line 2880
   at KT_Scan_Docs_Manager.Frm_Main.Bt_KT214CreateFileList_Click(Object sender, EventArgs e) in C:\Users\GTsag\Dropbox\Visual Studio\KT2-14 Scan Docs Manager\KT2-14 Scan Docs Manager\frm_Main.vb:line 148
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at KT_Scan_Docs_Manager.My.MyApplication.Main(String[] Args) in :line 81

标签: vb.net

解决方案


推荐阅读