GroupDocs.Conversion throws with Out of Memory exception for this test file

Sometimes, we may encounter corrupted files, or files with unknown extensions.
Will be good if GroupDocs.Conversion can fail gracefully when it encounters such situations.

Attached is a simple text file with filename “unknown.ext”:

sample.zip (211 Bytes)

Using the following piece of code:

GroupDocs.Conversion.FluentConverter.Load("unknown.ext").ConvertTo("unknown.pdf").Convert();

It will throw exception:

Unhandled Exception: GroupDocs.Conversion.Exceptions.GroupDocsConversionException: Exception of type 'System.OutOfMemoryException' was thrown. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.IO.MemoryStream.set_Capacity(Int32 value)
   at System.IO.MemoryStream.EnsureCapacity(Int32 value)
   at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at #=zrQ6_h4UFvAKeklZwiAJuWbC8d9ruwsNhkqyEgRo=.#=zDwEkrHY=()
   at #=zrQ6_h4UFvAKeklZwiAJuWbC8d9ruwsNhkqyEgRo=.#=zBUUz38NRe6pH(UInt32 #=zTHPuERo=, UInt32 #=zX6R5N1k=)
   at #=z2SjnS366aNpomxa3dg0xQxBblm5vUvUHuQ8$gHw=.#=zPn1zWWo=(Stream #=zprx9fQwmEYm0, Stream #=zr3sW9y78JnlT, Int64 #=z6LKql5U=, Int64 #=zrKH$FEo=, #=zcEtrG94Em$R$ilhRmzzQZup5qZlt_$cE$A== #=zICd4QTs=, Boolean #=zN1MUkMyX_nj1)
   at Aspose.Zip.LZMA.LzmaArchive.Extract(Stream destination)
   at    ..MoveNext()
   at  ? ..MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at  .(Exception )
   at  .(Object )
   at  .(MethodBase , Boolean)
   at  .(  )
   at  .  (  ,  )
   at  . ()
   at  .(Boolean )
--- End of stack trace from previous location where exception was thrown ---
   at  .(Exception )
   at  .(Object )
   at  . ()
   at  .?(  ,  )
   at  . ()
   at  .(Boolean )
--- End of stack trace from previous location where exception was thrown ---
   at  .(Exception )
   at  .(Object )
   at  . ()
   at  .(Object , UInt32)
   at  .(Boolean )
   at  .(Boolean )
   at  . ()
   at  .(Object[] , Type[], Type[] , Object[] )
   at  .(Stream , String, Object[] , Type[] , Type[] , Object[] )
   at  (Stream , String, Object[] )
   at  ? .MoveNext()
   at   (CancellationToken )
   at   .()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at   ..(Exception )
   at System.AggregateException.Handle(Func`2 predicate)
   at   .(CancellationToken )
   at    .Convert(CancellationToken )

Hello @jarrodwee ,

Thank you for reaching out. We will investigate this issue as soon as possible and get back to you once we have any updates.
In the meantime, could you please clarify what kind of result or behavior you would expect from GroupDocs.Conversion for .NET in this situation?
For example, would you prefer to have a more standardized message in case of such an exception, or would you rather have the ability to continue processing by catching such exceptions through regular logging?

Will be best if GroupDocs.Conversion actually catches the exception and let itself continue to the documentCompleted action handler.
In the documentCompleted handler, there’s a ConvertedStream in the ConvertedContext which can be set to null in such situation, i.e. to indicate that conversion was not successful. ConvertedFormat should also be set to FileType.Unknown as well.
Perhaps additional properties can also be added to ConvertedContext, e.g. the Exception itself, or otherwise, the error message and/or stacktrace to let the caller know the possible failure reason.

The above is especially important for recursive conversion whereby child documents are also converted. Any exception due to the conversion of one child should be caught and let the other children conversion continue on.

@jarrodwee ,

Thank you for sharing your thoughts on this matter.
We have logged this issue in our internal tracking system under the ID CONVERSIONNET-7846.
We will get back to you once we complete a more detailed investigation.