FileInfo.LastWriteTime discrepancies [Lakshan Fernando]

I recently investigated a customer issue of incorrect time reporting with FileInfo.LastWriteTime and thought of sharing this information in the blog. In the customer case, the last write time was off by about one hour for some files.   We depend on two Win32 APIs to get the file time information, GetFileAttributesEx in the normal…

6

SerialPort Encoding [Ryan Byington]

The SerialPort class uses the encoding specified by the SerialPort.Encoding property to convert strings and character arrays to bytes to send across the serial port. This encoding also gets used when reading from the serial port to convert bytes received by the serial port to strings and character arrays. <?xml:namespace prefix = o ns =…

6

SerialPort and DataReceived Event [Ryan Byington]

I have seen a few customers complain that their DataReceived event handler was never getting called and I thought I would share their problems here so you can learn from their mistakes. The problems revolve around the port not being open. This is sometimes as obvious as not calling SeiralPort.Close if you expect your DataReceived…

2

Using a MemoryStream with GZipStream [Lakshan Fernando]

We’ve seen cases where our customers have run into issues when using a MemoryStream with GZip compression. The problem can be frustrating to debug and I thought I’ll blog about it in the hope that others would avoid a similar issue. The code for this looks like this;           Byte[] compressedBuffer;         MemoryStream stream…

8

Using FileStream from Restricted User Accounts [Josh Free]

Every so often, I run into code that requests security permissions that are not needed.  Take the following code snippet as an example:      // open the file for reading FileStream fs1 = new FileStream(@”C:\Program Files\SomeFile.bin”,                                 FileMode.Open);     From the code comment, the developer is using the FileStream object to read the…

5

Reading a file in Managed Code [Lakshan Fernando]

Some of our new users to managed code take a little time to get used to the design pattern in reading a file. I thought I’ll enumerate through the most common patterns for their benefit;   Reading from a FileStream: Create a suitable buffer size – the default internal buffer size is 4k for a…

2

Using GZipStream for Compression in .NET [Brian Grunkemeyer]

One of the cool new features in Whidbey is a GZipStream class, which supports GNU’s zip utility (gzip).  For anyone with a Unix background, you’ve had to come across .tar.gz or .tgz files as you deal with the tedium that accompany downloading new source code & compiling new binaries for your Linux box, etc.  Well,…

8

How to set MACL from one directory to another? [Ravi Krishnaswamy]

A correct way to do this will be as follows:   // Get DirectorySecurity from source directory DirectorySecurity dsSrc = Directory.GetAccessControl(srcPath, AccessControlSections.Access);   // Transfer ACL security descriptor byte[] sdBinary = dsSrc.GetSecurityDescriptorBinaryForm(); DirectorySecurity dsDst = new DirectorySecurity(); dsDst.SetSecurityDescriptorBinaryForm(sdBinary, AccessControlSections.Access);   // Set new DirectorySecurity to destination directory Directory.SetAccessControl(dstPath, dsDst); //Destination    

2

DirectoryInfo.Name lacks security checks [Ravi Krishnaswamy]

This came out of one of our internal security review. I thought I would post it here for beware sake.     DirectoryInfo’s Name property currently requires no permission checks in and of itself, though you do need Read permission to construct a DirectoryInfo in the first place.  DirectoryInfo’s FullName property requires path discovery permission…

2

IO Exceptions will now reveal FullPath (if you have PathDiscovery access) [Ravi Krishnaswamy]

You might start noticing that in Whidbey Beta2, IO exceptions are handing out full qualified path which was previously regarded as secure information. Well, don’t be alarmed. This information is still secure and let me explain how.   IO classes often take in relative path (for ex, DirectoryInfo) but when you call some methods on them they…

2