Result: Failure Exception: System.Exception: Value cannot be null. (Parameter 'buffer')

Priya
Priya
1278 Points
37 Posts

Gettinng error with itext pdf during image imbeding:

 

Result: Failure Exception: System.Exception: Value cannot be null. (Parameter 'buffer') ---> System.ArgumentNullException: Value cannot be null. (Parameter 'buffer') at System.ArgumentNullException.Throw(String paramName) at System.IO.MemoryStream..ctor(Byte[] buffer) at iText.IO.Image.ImageTypeDetector.ReadImageType(Byte[] source) at iText.IO.Image.ImageTypeDetector.DetectImageType(Byte[] source) at iText.IO.Image.ImageDataFactory.CreateImageInstance(Byte[] bytes, Boolean recoverImage) at iText.IO.Image.ImageDataFactory.Create(Byte[] bytes, Boolean recoverImage) at iText.IO.Image.ImageDataFactory.Create(Byte[] bytes) at
Views: 108
Total Answered: 2
Total Marked As Answer: 1
Posted On: 04-Jun-2025 22:56

Share:   fb twitter linkedin
Answers
Rashmi
Rashmi
1200 Points
20 Posts
         

This means that a null value was passed to a method expecting a non-null byte[] buffer — specifically, to the constructor of System.IO.MemoryStream, which is then used by iText's ImageTypeDetector.

Here's what's happening in your call stack:

 

  1. You're passing a byte[] to ImageDataFactory.Create(...).

  2. That method internally tries to use ImageTypeDetector, which creates a MemoryStream using that byte array.

  3. But since the byte array (buffer) is null, the constructor throws an ArgumentNullException.

Posted On: 04-Jun-2025 22:58
Thanks
 - Priya  06-Jun-2025 00:03
Priya
Priya
1278 Points
37 Posts
         

Thanks. It's resolved by add null reference check.

Posted On: 06-Jun-2025 00:04
great!
 - Rashmi  09-Jun-2025 00:25
 Log In to Chat