Error: An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

后端 未结 4 871
粉色の甜心
粉色の甜心 2021-01-02 23:34

This is the part that crashes and gives me this error is when I try to copy a file to a certain location.

string startupDirectory = \"C:\\\\Users\\\\Tyler\\\         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 23:47

    This exception is triggered by a Windows error. It does not have a dedicated "this make absolutely no sense" error code, it just produces an "access denied" error code. Which .NET translates to a UnauthorizedAccessException.

    The "makes no sense" problem here is that you are trying to copy a directory with a file copy method. Directories are not files. Copying a directory requires creating a new directory first, then copying all of the files in the directory. .NET has a method for that, most C# programmers tend to think it is the 'wrong' namespace. It is Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory().

    But you'll need to think a bit more about this problem, it of course doesn't make sense to call the new directory "startup.exe". A probably meant to copy a specific file from the Startup directory, we can't guess what it might be.

提交回复
热议问题