An unhandled exception has occurred while executing the request. System.ArgumentNullException: Value cannot be null. (Parameter 'buffer')


Question: Why is MemoryStream having a Null buffer even after checking if the Stream contains any bytes?
The error says "An unhandled exception has occurred while executing the request.
      System.ArgumentNullException: Value cannot be null. (Parameter 'buffer')"



Login to See the Rest of the Answer

Answer: The reason for the error "An unhandled exception has occurred while executing the request.System.ArgumentNullException: Value cannot be null. (Parameter 'buffer')" is due to MemoryStream being Null, make sure that you are using the correct directive to check for Null buffer in the Memory Stream.

Use the keyword "is null" in C# like below:

if(memeryStream is not null && memoryStream.Lenght > 0)
//Execute

The null checking will execute first before checking the length, if you check the length first the Exception will throw.







For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]