"Value was either too large or too small for an Int16"

I’m experiencing the following exception when attempting to save a Word document using Aspose.Words (3.5.0.0):
Value was either too large or too small for an Int16.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.OverflowException: Value was either too large or too small for an Int16.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[OverflowException: Value was either too large or too small for an Int16.]
System.Convert.ToInt16(Int32 value) +69
୰.ட.ஶ(Byte[] ஷ, Int32 ஸ, Int32 ஹ, Int32 ஺, Int32 ஻)
୰.ட.get_୪()
୰.ᖊ.ᖙ(୯ ᒶ)
៥.ᤁ.ᤓ(୯ ᒶ, Double ᖐ, Double ᖑ, Boolean ᤐ)
៥.ᤁ.ᤑ(InlineShape ᣴ, Boolean ᤐ)
៥.ᤁ.ᤏ(InlineShape ᣴ, Boolean ᤐ)
ᣢ.ᣡ.VisitInlineShape(InlineShape shape)
Aspose.Words.InlineShape.Accept(DocumentVisitor visitor)
Aspose.Words.CompositeNode.ാ(DocumentVisitor ଯ)
Aspose.Words.Paragraph.Accept(DocumentVisitor visitor)
Aspose.Words.CompositeNode.ാ(DocumentVisitor ଯ)
Aspose.Words.Body.Accept(DocumentVisitor visitor)
ᣢ.ᣡ.ᢖ(Section ᗻ)
ᣢ.ᣡ.ᣪ(Document ᗙ, Stream Ը, String ߫)
Aspose.Words.Document.ധ(Stream Ը, String ߫, SaveFormat ന)
Aspose.Words.Document.Save(String fileName, SaveFormat fileFormat)
CMIS.Http.BinaryResourceHandler.ProcessOfficeDocumentRequest(DocumentStream theDoc, HttpContext context) in c:\documents and settings\steve\my documents\development components\enline\httphandlers\binaryresourcehandler.cs:274
CMIS.Http.BinaryResourceHandler.ProcessDocumentRequest(Int32 id, HttpContext context, Boolean doConvert) in c:\documents and settings\steve\my documents\development components\enline\httphandlers\binaryresourcehandler.cs:173
CMIS.Http.BinaryResourceHandler.ProcessDocumentRequest(Int32 id, HttpContext context) in c:\documents and settings\steve\my documents\development components\enline\httphandlers\binaryresourcehandler.cs:128
CMIS.Http.BinaryResourceHandler.ProcessRequest(HttpContext context) in c:\documents and settings\steve\my documents\development components\enline\httphandlers\binaryresourcehandler.cs:720
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

The relevant code looks like this:

Aspose.Words.License wlic = new Aspose.Words.License();
wlic.SetLicense(@Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.lic"));
Aspose.Words.Document wDoc = new Aspose.Words.Document(sourceFile.FullName);
wDoc.Save(xmlFile.FullName, SaveFormat.FormatAsposePdf); // EXCEPTION THROWN HERE

A sample “problem” document is attached.

- Steve Ford

The problem is caused by the ‘recycling’ image. It is a complex image composed from several objects. Aspose.Words sometimes has trouble handling such images. I have converted it to a bitmap and attached the corrected file.

Thanks for the info, Validimir. Are there any plans to fix this issue? We have hundreds of documents like this to process…

- Steve Ford

Support of composite images is a complex feature and I am afraid that it won’t be added soon. Just avoid using such images in your templates and substitute them with the bitmaps by taking a screenshot, cutting and saving in any photo editor. Sorry, no other workaround at the moment.

This issue was logged to our defect base as Issue #836. We will try to deal with it in the next 1-2 weeks.

Fixed in Aspose.Words 3.5.2 which can be downloaded from:
https://downloads.aspose.com/words/net