C# .NET - Denied access to write to a file in root of website from one library but not another.

Asked By Patrick Skelton on 22-Mar-13 01:12 PM
I have a website on my local IIS 7.5 server. The site has two libraries.  I will call them LibraryA and LibraryB. Both are copied to the same website sub-folder on build. LibraryA writes to a text file in the root directory of the website, and this works okay. However, when LibraryB raises an event, which triggers a call to the same file-writing function in LibraryA to write to the same text file, this fails with an exception which says access to the file is denied.
Why does one library appear to have permissions that the other doesn't?  And, given the fact that the actual file writing is always done by the same piece of code in LibraryA, I don't understand why one call should succeed and another fail.

The file writing is wrapped in a lock() {} to protect against threading errors and a using() {} to ensure the file is always closed after writing.
I have no idea what is going on here. Any help or suggestions at all would be very gratefully received.

Kind wishes, Patrick