Convert an empty file to JPG using C#

Hi. When I tried to convert an empty file (0 bytes) to a Jpg the following exception was thrown:

Attempted to read past the end of the stream.
Trace
   at   .(   , Int32 )
   at   .(   )
   at   .    (   )
   at GroupDocs.Conversion.Handler.ConversionHandler.Convert[T](Stream fileStream, LoadOptions loadOptions, SaveOptions saveOptions)
   at GroupDocs.Conversion.Handler.ConversionHandler.Convert[T](Stream fileStream, SaveOptions saveOptions)
   at yyy.xxx.Service.Document.AWSPDFFirstDocumentService.StoreDocumentContent(String docId, String docName, String extension, Byte[] content) in E:\Code\xxx\yyy.xxx.Services\Document\AWSPDFFirstDocumentService.cs:line 47
   at yyy.xxx.Service.Document.AWSPDFFirstDocumentService.Store(Document document) in E:\Code\xxx\yyy.xxx.Services\Document\AWSPDFFirstDocumentService.cs:line 56
   at yyy.xxx.Service.Document.SecureDocumentService.Store(Document document) in E:\Code\xxx\yyy.xxx.Services\Document\SecureDocumentService.cs:line 175
   at yyy.xxx.UI.Web.Api.Controllers.MatterDocsController.Post(String matterId, DocumentToMatterRequest theRequest) in E:\Code\xxx\yyy.xxx.UI.Web.Api\Controllers\MatterDocsController.cs:line 91
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()

I think it’s good either to throw a meaningful exception or much preferely generate a blank result (In my case an image with the given size but blank)

Hi Leap,

Thank you for spotting the issue in loading a blank document.

We are able to notice the same behavior and will discuss further with product team to figure out how to handle such scenario at the API level.

Best Regards

The issues you have found earlier (filed as CONVERSIONNET-783) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by groupdocs.notifier.