1
Vote

NullReferenceException when trying to insert an empty file

description

When changed the test console project. I got NullReferenceException when the loop hit a file with size 0.
 
namespace TestConsole
{
class Program
{
    static void Main(string[] args)
    {
        string dbFile = @"C:\Temp\MvcDemo.dat";
        string[] files = Directory.GetFiles(@"D:\folder", "*", SearchOption.AllDirectories);
        Parallel.For(0, files.Length, (i) =>
        {
            Console.WriteLine("Starting " + Path.GetFileName(files[i]));
            FileDB.Store(dbFile, files[i]);
            Console.WriteLine("Ended " + Path.GetFileName(files[i]));
        });
        Console.ReadLine();
    }
}
}

comments

mbdavid wrote Dec 12, 2011 at 10:42 AM

Hi, thanks for your comments. I will add more parameter validations on all public methods.

wrote Feb 14, 2013 at 3:02 AM

shoky wrote Jun 6, 2013 at 5:01 AM

Same thing happens when I try to add file using 0 size stream.

ie.

var stream = new MemoryStream ( new byte[0]);
FileDB.Store( "archive.fdb","testfile", stream );