Visual Studio and .NET Framework Home
System.IO.File.WriteAllBytes() fails on large byte arrays
8/28/2009 9:06:29 AM
User(s) can reproduce this bug
System.File.IO.WriteAllBytes() fails when writing a large byte array to a network drive. Original file is about 80 MB. Small files work ok. Not sure at what size they start to fail.
I've tried writing to UNC paths on 2003, 2008 and Samba. Also tried a mapped drive (e.g F:\temp\File.pdf). All fail. There are no quotas in place and permissions are okay.
System.IO.File.Copy() and System.IO.File.Move() both work on the same file without error.
.NET Framework 3.5 SP1
Operating System Language
Steps to Reproduce
byte myfile = File.ReadAllBytes(@"c:\temp\Dividers.pdf");
System.IO.IOException was unhandled
Message="Insufficient system resources exist to complete the requested service.\r\n"
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.WriteCore(Byte buffer, Int32 offset, Int32 count)
at System.IO.FileStream.Write(Byte array, Int32 offset, Int32 count)
at System.IO.File.WriteAllBytes(String path, Byte bytes)
at Test_Environment.Program.Main(String args) in C:\Users\bsteele\Documents\Visual Studio 2008\Projects\MPG.Typensave\Test_Environment\Program.cs:line 25
at System.AppDomain._nExecuteAssembly(Assembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
Should write file to specified location.
TAP Code (if applicable)
You can indicate your satisfaction with how Microsoft handled this issue by completing this quick
3 question survey
to post a comment.
Please enter a comment.
on 10/5/2009 at 2:38 PM
The status of this ticket just changed to fixed. Updating the documentation doesn't really fix the problem...I still cannot write a 66MB file to a network drive.
Will the underlying Win32 library ever be modified? How about the x64 library?
on 9/17/2009 at 1:29 PM
Sorry for the issue with WriteAllBytes() throwing IOException when writing large files (64MB+) to network paths. The underlying Win32 WriteFile API limits network write operations to 65,535 bytes per write. In order to write large files over the network, the writes will have to be done in multiple chunks, each under 64MB.
I will make sure the System.IO documentation is updated on http://msdn.microsoft.com/ to reflect this size limitation when working with network paths.
Base Class Library Development
on 8/31/2009 at 6:15 AM
Will the status of this ticket be updated if it's fixed?
on 8/31/2009 at 12:20 AM
Thanks for your feedback. We are routing this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.
Visual Studio Product Team
to post a workaround.
Please enter a workaround.
on 8/28/2009 at 9:28 AM
Write the file to a local disk, then use System.IO.File.Move() to move the file to the UNC path.
Something like this:
string path = "\\server\share\myfile.pdf";
string tempPath = Path.GetTempFileName() + "." + Path.GetExtension(path);
© 2014 Microsoft