We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

InsertImage error: Stream length must be non-negative and less than 2^31 - 1 - origin

Hi


I’m well and truly stumped!

We’ve build an enormously powerful reporting engine on ASPOSE, which have been running smoothly for over 2 years now.

One of the Reporting Sections use Aspose.Words.DocumentBuilder.InsertImage() to add an image on the Cover Page. This is pretty old functionality which never gave any problems as far as I can remember.

However, last week, two of our users started getting an error on their machines which no one else seems to get. I’ve never seen this error message before myself…ever!

System.ArgumentOutOfRangeException: Stream length must be non-negative and less than 2^31 - 1 - origin.
at System.IO.MemoryStream.Seek(Int64 offset, SeekOrigin loc)
at x38a89dee67fc7a16.xdd1b8f14cc8ba86d.x5d8883ce13fdc89f(Stream xcf18e5243f8d5fd3)
at x38a89dee67fc7a16.xdd1b8f14cc8ba86d.x16a7fb03c627ebfb(Stream xc8f3f690897a858e, xfe2ff3c162b47c70 x0182a6dae298f8a4)
at x011d489fb9df7027.x8e500baeffc6e539.get_x8d0c72c5b2891cbc()
at Aspose.Words.DocumentBuilder.InsertImage(Byte[] imageBytes, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(Stream stream, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(Image image, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)

The image file is about 900000 characters long, so it is definitely not larger than 2^31. It also cannot be that they’re not getting the image at all, as they’re connecting to the same database as everybody else.

I would appreciate any clues which you might be able to provide to track down the cause of this problem.



Hi Hanno,


Thanks for your inquiry. To ensure a timely and accurate response, it would be great if you please create a standalone runnable simple application (for example a Console Application Project) that helps me reproduce the same exception on my end and attach it here for testing. As soon as you get this simple application ready for me, I’ll start investigation into your issue and provide you more information.

Best regards,

Hi Awais.


I would love to do that, but the trouble is that I can’t reproduce the problem myself. It only happens on the machines of two users who are in a different city.

I have reason to suspect the error originates from Microsoft’s MemoryStream class, but since I can’t access the ASPOSE code to see how it’s used, I was hoping you guys might have a quick look at the code and see if you have any ideas that might help me resolve the issue. It’s a stretch, I know, but right now, I’m willing to try anything.


Hi Hanno,


Thanks for your inquiry. Unfortunately, it is difficult to say what the problem is without code. I would suggest you please ask those customers to upgrade to the latest version of Aspose.Words and see how it goes. I hope, this helps.

In case, the problem still remains, please supply us with the following information.
  • What environment are they running on?
    • OS (Windows Version)
    • Architecture (32 / 64 bit)
    • .NET Framework version
    • Any Third Party Libraries / SDK in addition to Aspose Products
  • Please supply us with a sample image file which is causing this issue.
  • Does this happen with one image in particular or all images you try?

As soon as you get these pieces of information to us we’ll start our investigation into your issue.

Best regards,

Hi Awais


The Aspose version is definitely not the problem: We released the Aspose assemblies with our application to all our users using Click Once - so they’re using the same version as everybody else. (Which is ASPOSE.WORDS 13.2)

They’re using Windows 7

Version 6.1 (Build 7600)
We have noticed that this is only the machines giving the problem. Other machines that’s working fine is running (Build 7601: Service Pack 1). We’re going to install the service pack on their machines to see if that fixes the problem.

We’re still running on 32 bit machines.
Dot Net framework is 4.0.30319. We’ve uninstalled our application and dot net framework from the problem machines, and reinstalled everything - to no avail.

The only other package we use to a large degree is Janus Controls, but I don’t think those would interfere with Document generation at all. For our documents, we’re only using ASPOSE.

For context, I’ve attached the method in my Report Engine that deals with adding images. The Error arise on this line:
Aspose.Words.Drawing.Shape docImage = _docBuilder.InsertImage(image);

We generate the document from scratch, and because of this error, no document is generated. I therefore can’t say with 100% certainty that the problem only affects this one image, but I think I have good reason to suspect so:

(See attached example:) The have two logo images which we place on the first page header and page header. These images are quite small. The Cover Page, however, only comes up after the cover letter, and it is the image on the Cover Page (0.9 MB) that’s causing the problem. I would guess that by the time the Cover page is rendered, the Logo images on the Page headers is already rendered.

I know definitely that it is the image on the cover page that’s breaking, and not the page headers: Since we’re building the report using separately compiled building blocks, the stack trace tells me exactly where the error originates from.

NB: Please note as I mentioned before: The error does not originate from the ASPOSE code, but rather from the underlying Microsoft code. I’ve searched around on the internet, and it seems that MS raises this exception in the Seek or SetLength Method of the MemoryStream class.

http://social.msdn.microsoft.com/Forums/vstudio/en-US/838ac34a-179b-41a6-93a9-8cc25226d821/how-to-convert-string-into-stream

http://cscoder.wordpress.com/

That’s why I suspect that someone who has access to the ASPOSE code to see how it is used, might have some useful insight as to why the error occurs. It seems that these methods determine the reading position of the byte array, and somehow the position jumps to below 0 or above 2 billion.








Hi Just a quick update.


I just heard that a third user from our Port Elizabeth branch also reported the error (The other two was from our Durban branch) In all three cases, Service Pack 1 was not installed. This gives me reasonable confidence that that might be the problem. I’ll let you know as soon as I get feedback.

Ok, I can confirm, the issue was the lack of Service Pack 1. Case Closed :slight_smile:

Hi Hanno,


Thanks for the additional information. It’s great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,