Email and Cells. Index and count must refer to a location within the buffer. Parameter name: bytes

Hello!
I have a program, that downloads attachment from an email through Aspose.Email 22.4 and parses data in it with Aspose Cells 22.4 under .Net Framework 4.5
Everything worked fine for a while, but some time ago I started to get error, while getting the workbook:
Index and count must refer to a location within the buffer. Parameter name: bytes

How can i solve it? There is no chance to change an excel file…

Code:

using (var client = EWSClient.GetEWSClient("ServerUri", credential))
{
	var mailbox = client.GetMailboxInfo("SomeEmail");
	var messages = client.ListMessages(mailbox.InboxUri);
	var ordered = messages.OrderBy(s => s.Date);
    foreach (var messageInfo in ordered)
    {
        var mailMessage = client.FetchMessage(messageInfo.UniqueUri);			
		foreach (var attachment in mailMessage.Attachments)
        {
            if (string.Compare(attachment.Name, "SomeFileName", StringComparison.OrdinalIgnoreCase) != 0)
                continue;

			//Get bytes for inline read Excel
            var len = attachment.ContentStream.Length;
            var buffer = new byte[len];
            attachment.ContentStream.Read(buffer, 0, (int) len);

			//Save file to folder
            var fileNameToHistory = Path.Combine("SomePathToFolder", "SomeXLSFileName.xls");
            attachment.Save(fileNameToHistory);
			
			//Read data from attachment
			using (var stream = new MemoryStream(buffer))
            {
                stream.Seek(0, SeekOrigin.Begin);
                workbook = new Workbook(stream);  // <<-- Error here
            }
			
			//Read data from saved file
			using (var file = File.OpenRead(fileNameToHistory))
            {
                var workbook = new Workbook(file);  // <<-- Error here
            }
        }
    }
}

@rumoex,

Could you please share a standalone sample project with resource files to reproduce the issue on our end, we will check it soon. Also, did you try using latest version of the APIs (e.g., Aspose.Email and Aspose.Cells) if it makes any difference?

PS. please zip the project and files prior attaching.

I’ve made a ConsoleApp where copied some code to reproduce error (all the config is in the Program.cs)
ConsoleApp2.zip (5.7 KB)
I also attach the .xls file, that is saved from Email (unzip it)
w.zip (942.1 KB)

There is a commented code in ExcelHelper.cs, that I used to resave file using Marshal. After resaving the file opens correctly

@rumoex,

I tested your scenario/case with your sample code by providing test URL, login, pwd and other details. But when I tried to run the code, it gives error on ProcessMails() method (ProcessFile() works fine). I am not sure if the issue is with Aspose.Cells APIs by any means or with Aspose.Email or due to other configurations. Could you please separate the issue and use only Aspose.Cells to reproduce the issue on our end. If you are successful, kindly do share sample (runnable) code for it. This way, it will be confirmed that the issue is with Aspose.Cells and we can evaluate the issue to figure it out soon.

@rumoex,

Would you please save the data in your “buffer” to a file and then load the workbook from the saved file to check whether the error can be reproduced? If so, please send us the saved file so we can trace and fix the issue.

The saved from “buffer” file is in my previous message, named w.zip (it’s not allowed to upload .xls files here…)

I’ve commented working with email an left just opening physical file
Here is the project:
ConsoleApp2.zip (5.7 KB)

@rumoex,
After deleting the relevant parts of the email. I can successfully run your newly uploaded project without any exceptions.

You run it for .xls file that I posted in zip? If so - that’s really interesting…

@rumoex,
Please check the attachment.result.PNG (65.0 KB)

Well…I use 22.4 version and get such an error:
image.png (17.9 KB)

@rumoex,
Please test it with the latest version Aspose. Cells 23.4.

I don’t have a license for 23.4…
I’ve tried on 23.0 and it works! Thank you)

Just a little question - is there some page, where I can download not latest Aspose.Total DLLs, like this page?

@rumoex,
Thank you for your feedback. Please check the link: