This should be one of the strangest exceptions I have ever seen. When using the static File.WriteAllText method to write files, a specific file name cannot be written: "PRN". You can recreate this with a simple one liner:
File.WriteAllText("c:\\Temp\\PRN.txt", "write this to a file");
I tried different extensions, I tried writing to different folders using this method, but in all cases I get the following exception when trying to write a file with this specific file name:
FileStream will not open Win32 devices such as disk partitions and tape drives. Avoid using \ "\\. \\" on the go.
stack trace is as follows:
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost) at System.IO.File.WriteAllText(String path, String contents) at WriteAllTextThrowsExceptionWithPRN.UnitTest1.TestMethod1() in c:\Users\ntregillus\Documents\Visual Studio 2013\Projects\WriteAllTextThrowsExceptionWithPRN\WriteAllTextThrowsExceptionWithPRN\UnitTest1.cs:line 14
Any ideas why this will happen? I think I'm going to replace it with my own file author, but I found him crazy, while the file name “PRD” would cause this system to explode.