.net - Random UnauthorizedAccessException while reading a file in %temp% -
i have process writes file in temp directory. file being written without shared read access, if attempts read file while being written, ioexception
thrown, which fine.
in rare cases, seem getting unauthorizedaccessexception
while attempting read file. i'm (from logs) file not being written to, can't see other reason wouldn't have access it.
also, process runs visual studio extension, means has same permissions parent process (visual studio itself).
here's how attempt open file:
new filestream(cachefilename, filemode.open, fileaccess.read, fileshare.read);
sometimes, line throws unauthorizedaccessexception
. ideas why?
it not sharing problem, generates sharing violation error , that's reported ioexception.
there 2 decent explanations unauthorizedaccessexception. 1 logical one, file got created custom acl denies access. in case you'll need know lot more process created file , whack on head stops doing this. controlling user account that's used process might important.
the second explanation associated vagaries of having many processes creating files , directories in temp directory. rather important files created there transactional , allow system generate file names, ensuring there's never name collision. having process create file , allowing open asking trouble. you'll unauthorizedaccessexception when temp directory contains directory same name of file trying open.
debugging problem tricky if happens infrequently , file(s) disappear again. can enable auditing log failed attempts @ opening file.
Comments
Post a Comment