I am getting the following exception:
[01/14/2026 19:34:01 > 2fe697: INFO] [19:34:01 DBG] Program.ConvertHtmlToPf: Html file ‘C:\home\ConvertHtmlToPdf\Output\whitby-class-upgrade.html’ is created successfully
[01/14/2026 19:34:03 > 2fe697: INFO] [19:34:03 ERR] Error Occurred while generating PDF for project: whitby-class-upgrade.cshtml
[01/14/2026 19:34:03 > 2fe697: INFO] System.AggregateException: One or more errors occurred. (Sequence contains no elements)
[01/14/2026 19:34:03 > 2fe697: INFO] —> System.InvalidOperationException: Sequence contains no elements
[01/14/2026 19:34:03 > 2fe697: INFO] at System.Linq.ThrowHelper.ThrowNoElementsException()
[01/14/2026 19:34:03 > 2fe697: INFO] at System.Linq.Enumerable.First[TSource](IEnumerable1 source) [01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.StorageService.<>c__DisplayClass21_0.<<UploadFileAsync>b__0>d.MoveNext() [01/14/2026 19:34:03 > 2fe697: INFO] --- End of stack trace from previous location --- [01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.StorageService.UploadFileAsync(String file, String remoteFileUri, String storageName) [01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.StorageApi.UploadFileAsync(String file, String remoteFileUri, String storageName) [01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.UploadAsync(String folder, String basePath, String[] files) [01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.PrepareRequestBodyAsync(ConverterBuilder builder) [01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.<>c__DisplayClass12_0.<<ExecuteConversionAsync>b__0>d.MoveNext() [01/14/2026 19:34:03 > 2fe697: INFO] --- End of stack trace from previous location --- [01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.ExecuteConversionAsync(ConverterBuilder builder, IObserver1 observer)
[01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.ConvertAsync(ConverterBuilder builder, IObserver1 observer) [01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.ConvertApi.ConvertAsync(ConverterBuilder builder, IObserver1 observer)
[01/14/2026 19:34:03 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.ConvertApi.ConvertAsync(String inputFilePath, IList1 resources, String outputFilePath, ConversionOptions options, IObserver1 observer)
[01/14/2026 19:34:03 > 2fe697: INFO] — End of inner exception stack trace —
[01/14/2026 19:34:03 > 2fe697: INFO] at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[01/14/2026 19:34:03 > 2fe697: INFO] at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) [01/14/2026 19:34:03 > 2fe697: INFO] at System.Threading.Tasks.Task1.get_Result()
[01/14/2026 19:34:03 > 2fe697: INFO] at ConvertHtmlToPdf.Program.ConvertHtmlToPf(Project project) in C:\Development\Clients\ConvertHtmlToPdf\Program.cs:line 177
[01/14/2026 19:34:03 > 2fe697: INFO] at ConvertHtmlToPdf.Program.GeneratePDFs(List`1 projects) in C:\Development\Clients\ConvertHtmlToPdf\Program.cs:line 131
-
The exception
System.InvalidOperationException: Sequence contains no elementsoccurs during the upload of an HTML file to Aspose Cloud Storage, specifically in theUploadFileAsyncmethod . This indicates an issue within the SDK’s internal logic when processing the file upload, likely due to an unexpected empty collection being passed toEnumerable.First(). -
A related issue has been reported in the Aspose forum where users encountered a
504 Gateway Timeouterror during file uploads and conversions . Such timeouts may reflect temporary server-side problems affecting the Aspose Cloud services, potentially contributing to the failure observed in your case . -
Based on the stack trace, the error originates from a call to
Enumerable.First()on an empty sequence, suggesting that an operation expected at least one element but found none . This might stem from a failed resource lookup or a misconfigured file path during the conversion process .
To address this issue, consider the following steps:
- Verify that the HTML file exists at the specified path and is accessible.
- Confirm that the Aspose Cloud service is operational and not experiencing outages .
- Retry the conversion after some time, especially if the error correlates with known service disruptions.
If the problem persists, it may be necessary to investigate further into how the SDK handles file uploads or whether there is a bug in the version of the SDK being used. You can also reach out to Aspose support for assistance .
Hi, thanks. I tried again, however I still see the same error:
[01/15/2026 14:29:50 > 2fe697: INFO] System.AggregateException: One or more errors occurred. (Sequence contains no elements)
[01/15/2026 14:29:50 > 2fe697: INFO] —> System.InvalidOperationException: Sequence contains no elements
[01/15/2026 14:29:50 > 2fe697: INFO] at System.Linq.ThrowHelper.ThrowNoElementsException()
[01/15/2026 14:29:50 > 2fe697: INFO] at System.Linq.Enumerable.First[TSource](IEnumerable1 source) [01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.StorageService.<>c__DisplayClass21_0.<<UploadFileAsync>b__0>d.MoveNext() [01/15/2026 14:29:50 > 2fe697: INFO] --- End of stack trace from previous location --- [01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.StorageService.UploadFileAsync(String file, String remoteFileUri, String storageName) [01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.StorageApi.UploadFileAsync(String file, String remoteFileUri, String storageName) [01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.UploadAsync(String folder, String basePath, String[] files) [01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.PrepareRequestBodyAsync(ConverterBuilder builder) [01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.<>c__DisplayClass12_0.<<ExecuteConversionAsync>b__0>d.MoveNext() [01/15/2026 14:29:50 > 2fe697: INFO] --- End of stack trace from previous location --- [01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.ExecuteConversionAsync(ConverterBuilder builder, IObserver1 observer)
[01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.Services.ConversionService.ConvertAsync(ConverterBuilder builder, IObserver1 observer) [01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.ConvertApi.ConvertAsync(ConverterBuilder builder, IObserver1 observer)
[01/15/2026 14:29:50 > 2fe697: INFO] at Aspose.HTML.Cloud.Sdk.ConvertApi.ConvertAsync(String inputFilePath, IList1 resources, String outputFilePath, ConversionOptions options, IObserver1 observer)
@devrajbanerjee It sounds like it can’t upload file that you try to convert. So it either can’t access the file or path to the file is wrong. Could you please post how the calling code looks?
Also, as an alternative you can try to use API directly as described here: REST API Overview – Aspose.HTML Cloud
Hi, we have not changed the path, nor the code in a year or so. Here is the calling code we have been using:
Log.Debug($"Program.ConvertHtmlToPf: Processing the project {project.Name}");
var client = new HtmlApi(config?.HtmlApiClientId, config?.HtmlApiClientSecret).ConvertApi;
// Create an options object and specify options for HTML to PDF conversion
var options = new PDFConversionOptions()
.SetHeight(11) // format in inches
.SetWidth(9) // format in inches
.SetLeftMargin(0)
.SetRightMargin(0)
.SetBottomMargin(0)
.SetTopMargin(0);
#pragma warning disable CS8602 // Dereference of a possibly null reference.
string htmlTemplate = Path.Combine(config.SrcDir, config.HtmlTemplate);
#pragma warning restore CS8602 // Dereference of a possibly null reference.
//var resources = new List();
string inputFileName = project.Name.Replace(".cshtml", ".html");
string inputFilePath = Path.Combine(config.DstDir, inputFileName);
string htmlContent = System.IO.File.ReadAllText(htmlTemplate);
htmlContent = ReplaceToken(htmlContent, project);
// Save the modified content to the output file
File.WriteAllText(inputFilePath, htmlContent, System.Text.Encoding.UTF8);
Log.Debug($"Program.ConvertHtmlToPf: Html file '{inputFilePath}' is created successfully");
var outputFileName = project.Name.Replace(".cshtml", ".pdf");
var outputFilePath = Path.Combine(config.DstDir, outputFileName);
ConvertResultFile result = client.ConvertAsync(inputFilePath, resources: null, outputFilePath, options).Result;
if (result.Status == ConvertResultStatus.Completed)
{
Log.Debug($"Program.ConvertHtmlToPf: PDF file '{outputFilePath}' is created successfully");
Hi @devrajbanerjee thank you for the details. Generally this functionality works fine. We can see this from logs and our testing. In your case it fails not on conversion but on the step before - on uploading file to the storage. It means that either something wrong with the file or with your account.
Could you please check 2 things:
- Login to your aspose account to see if there are no messages regarding storage or quota usages. We can’t see this on our end.
- Try to convert some simple test file.
Please let us know the result.
We will release this week update for the .NET SDK and make it return more detaild information for the case.
Thank you. We could resolve the issue.