I wonder if anyone else is having a similar issue.
I have a simple file copy code in my application, which can be simplified as below (and my user I opened VS2013 to debug the code has full control on both the source and target folder hierarchy - this wasn't so for some reason, I tried running VS in admin mode which didn't work, then I manually applied full-control to the user, and anyways the error complains about the source folder)
// sourcefile was thought to be @"C:\tfs\Dev\Source\some-module\bin\Debug\mybinary.dll";
// retrieved through an environment variable, but was pointing to the folder instead of the file inside
Directory.CreateDirectory(myfolder);
File.Copy(sourcefile, Path.Combine(myfolder, Path.GetFileName(sourcefile)), true);
This code worked happily until I tried it today on my local machine (and still works on my testbed machine). But for some reason, it started throwing the error below:
System.UnauthorizedAccessException: Access to the path 'C:\tfs\Dev\Source\some-module\bin\Debug' is denied.
Result StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
Thinking it may be a file-lock issue I rebooted and tried it again afresh but failed.
The folder for source has Read-only attribute and thinking this may be a problem (which is weird), I started trying unsetting it but cannot. Then I moved the folder out of the tfs workspace to another folder (under c:\users\my-user..) and still cannot remove the read-only attribute (it seems to work, but checking again shows the same attribute on the file). I even frantically tried unsetting read-only on all the parent folders then gave up as it's in vein. And must not be in any way related to the original problem.
I double-checked similar so questions and thoughts and am running out of options.
Win7, .net 4.5.2, VS2013 are some configurations.
additional experiments, update I tried using Directory.CreateDirectory on the sourcefile directory with security rules with full permission to current user, doesn't change anything. Why would it complain about the sourcefile directory to start with??