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

Free Support Forum - aspose.com

After .NET upgrade getting error At most 4 elements (for any collection) can be viewed in evaluation mode

We are using Aspose.Pdf version Aspose.Pdf.11.7.0. SubscriptionExpiry 20170104

We recently upgraded .NET from 4.6.2 to 4.7.2. And randomly we started getting error

System.IndexOutOfRangeException: At most 4 elements (for any collection) can be viewed in evaluation mode.
at Aspose.Pdf.Document.(Int32 )
at Aspose.Pdf.PageCollection.(Int32 )
at Splitter.GetHeaderImages(Document sourcePdf, YAxisCropper markerHelper)

The code where the exception occurs

    private IList<Aspose.Pdf.Image> GetHeaderImages(Document sourcePdf, YAxisCropper markerHelper)
            var headerImages = new List<Image>();
            for (int i = 1; i <= sourcePdf.Pages.Count; i++)
                var sourcePage = sourcePdf.Pages[i];
                var pageWidth = Convert.ToInt32(sourcePage.ArtBox.Width);
                var pageHeight = Convert.ToInt32(sourcePage.ArtBox.Height);
                var headerBoxes = markerHelper.GetHeaderBoxes(i, pageWidth, pageHeight);
                foreach (var headerBox in headerBoxes)
                    var img = GetCroppedImage(sourcePage, headerBox);
            return headerImages;

Aspose.PDF is used many places in our application. We are using & setting valid production license for sure otherwise we would be getting evaluation warning everywhere. This was existing code in production for 2+ years with .NET 4.6.2.
Interestingly, after the exception when we run the the same PDF file through same routine again then it works fine.


It is hard to determine the reason behind the issue that you are facing. Furthermore, you are using a quite old version of the API and many classes and methods have been obsolete in it. We are not providing support against older versions of the API and always recommend using the latest available version. Please try to upgrade the version of your API to the latest one and let us know in case you still face any issues. We will further proceed to assist you accordingly.

Is there any harm settings the license again? We set the license at the application start (ASP.NET Web API)

           var path = "aspose license file path";
           if (File.Exists(path))
                using (Stream licStream = new FileStream(path, FileMode.Open))
                    // set aspose cell license
                    licStream.Seek(0L, SeekOrigin.Begin);
                    Aspose.Cells.License cellLicense = new Aspose.Cells.License();

                    // set aspose pdf license
                    licStream.Seek(0L, SeekOrigin.Begin);
                    Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();

                    // set aspose barcode license
                    licStream.Seek(0L, SeekOrigin.Begin);
                    Aspose.BarCode.License barcodeLicense = new Aspose.BarCode.License();

                    // set aspose OCR license
                    licStream.Seek(0L, SeekOrigin.Begin);
                    Aspose.OCR.License ocrLicense = new Aspose.OCR.License();

is there any harm setting license file multiple times?


There is no harm in setting the license multiple times however, it is not a recommended and good practice. We always recommend setting the license at the very start of the application. In case you are facing some issues, try setting license using file path instead of stream and share a sample application with us in case you still face any issues.