A while ago, I discussed some interesting behavior of File.Exist function in .Net. Recently I found out that File.Copy is just as elusive when UNC is involved.

There are many articles out there discussing problems developers have encountered with File.Copy. While most of those problems are user problems, a few of those problems were simply mysterious to say the least. Here is the problem I encountered recently:

I have written a C# application that moves files from one NAS to local machine. The user under which the application is launched belongs to an AD group which has Administrative rights on both locations. The strange thing is that once a while (for example, one out of a hundred files) I would receive an Access denied exception saying that I do not have the rights to copy a particular file from the UNC location. With the same user credential as the the application however, I could manually copy the problematic file without any issues.

At first, I thought that it might have just been an transient error, but multiple tries would error out on the exact same file (all together, there were hundreds of files). Interestingly enough, this file has exactly the same permissions as other files that were successfully copied. Even though this file is a bit larger than the other files, my applications had successfully copied many larger files before…

One discussion thread I found suggested that it might be a delegation issue. But given that the application was able to move many other files except the once-awhile hitch-ups, I doubt that it was the permission issue.

The only thing I can think of is that the copy might simply have encountered a problem (e.g. disk problem, maybe), but somehow the wrong error message got returned. While, I wouldn’t be surprised if this is indeed the case, as I have encountered similar problems before.

Anyway, I will see if I can figure this out…

Be Sociable, Share!