📉Files - NKS0012
Use Copying.CopyFileOrDir()
Last updated
Use Copying.CopyFileOrDir()
Last updated
This analyzer provides the following strings:
Context | String |
---|---|
This code analyzer detects the usage of Copy
from the standard File
class found in the System.IO
namespace.
Using File.Copy()
, path neutralization doesn't take place to ensure that we have the correct absolute path. This causes some of the filesystem operations to operate on files, which are located in the wrong place, and, therefore, errors throw about a target not being found.
A solution to this problem was made with CopyFileOrDir()
, because it takes care of the absolute paths and tries to reduce this kind of error caused by passing relative directories to the arguments.
To get a brief insight about how this analyzer works, compare the two code blocks shown to you below:
You can suppress this suggestion by including it in the appropriate place, whichever is convenient.
For more information about how to suppress any warning issued by the Nitrocid analyzer, visit the below page:
We recommend that every caller which use this function use the recommended abovementioned method.
Error List
Caller uses File.Copy
instead of Copying.CopyFileOrDir()
Suggestion Box
Use Copying.CopyFileOrDir()
instead of File.Copy
Description
Copying.CopyFileOrDir()
neutralizes the provided paths to their absolute correct paths, while File.Copy
operates at the executable directory (Environment.CurrentDirectory
), which may not be what you want.