Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1489

Read throws NullReferenceException when using a seekable download stream

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2
    • Affects Version/s: 2.1
    • Component/s: GridFS
    • Labels:
      None
    • Environment:
      Windows 7 x64

      In my application, I need to support downloading arbitrary chunks of a GridFS file per request. To do this, I'm using bucket.OpenDownloadStream (setting Seekable to True in the options), and Stream.Read.

      I get a NullReferenceException in GridFSSeekableDownloadStream.GetSegment at:

      var segmentCount = _chunk.Length - segmentOffset;
      

      because _chunk is null.

      Here is a test that can be added to GridFSDownloadStreamBaseTests

      [Test]
              public void Read_should_not_throw(
                  [Values(0.5, 1.0, 1.5, 2.0, 2.5)] double contentSizeMultiple,
                  [Values(false, true)] bool async, 
                  [Values(false, true)] bool seekable)
              {
                  var bucket = CreateBucket(128);
                  var contentSize = (int)(bucket.Options.ChunkSizeBytes * contentSizeMultiple);
                  var content = CreateContent(contentSize);
                  var id = CreateGridFSFile(bucket, content);
                  var options = new GridFSDownloadOptions() {Seekable = seekable };
                  var subject = bucket.OpenDownloadStream(id, options);
      
                  var buffer = new byte[contentSize];
      
                  if (async)
                  {
                      subject.ReadAsync(buffer, 0, contentSize).GetAwaiter().GetResult();
                  }
                  else
                  {
                      subject.Read(buffer, 0, contentSize);
                  }            
              }
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            rich.quackenbush@gmail.com Rich Q
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: