Insert Image using Word Mail Merge with XML Data fails

MailMerge fails with an 400 ERROR

We have log that the error started this morning (2022-01-13 03:37 EST) Some calls were with success, others failed.

Since 2022-01-13 03:52 EST, all mailmerge failed with “Error: ExecuteMailMerge. Exception: There is an error in XML document (1, 40). => was not expected…”

No code changed on our side.
Any idea where to look ?

Any change log of the API that would be breaking ?

@Qc050.ETI

We are sorry for the inconvenience. I have tested the scenario with my sample template and data but was unable to replicate the issue. We will appreciate it if you please share your sample code and documents(template/data file) for investigation. We will look into these and will guide you.

We currently use version 21.10.0.

AsposeError.zip (66.3 KB)

@Qc050.ETI

Thanks for sharing the sample template and the data file. Please note using Aspose.Words Cloud mail merge feature you populate can populate an image from a publicly accessible HTTP path or a cloud storage path.

<Img>875a0b06-2fb3-4df0-afb1-a65740be1d57</Img>

Your data have an issue with the referenced image, it is not a valid image path. For testing, I replaced it with a public accessible HTTP path and the image is populating without any issue.

I can’t pass URL for my image since the image is in the storage defined for the application. In our case it is an Azure storage. It should fetch the image from that location without needing a URL. This was working two days ago.

Thank you!

@Qc050.ETI

Yes, you can use an image from your cloud storage. I will appreciate it if you please share your sample code along with the credentials in a private message. We will further investigate the issue.

P.S: You can use flag button in my post for the private notification.

Here is the sample code

@Qc050.ETI

As requested above, please share your credentials(Client Id/Client Secret) in the private message as well. It will help us to reproduce and investigate the issue.

@Qc050.ETI

Thanks for sharing your sample code and credentials. I have tested the scenario using Aspose.Words Cloud SDK for .NET 22.1 version and your above shared template/data. However, please note I’m unable to find the referenced image file(specified in XML file) at your cloud storage. It looks like a folder name instead of an image file name.

<Img>875a0b06-2fb3-4df0-afb1-a65740be1d57</Img>

I have uploaded a sample image google.jpg to your cloud storage root updated the XML file. And used the following code for testing the mail merge API. I am still unable to replicate your reported exception. You may please check the template, data and output file in the Temp folder in your cloud storage. Please ensure that the referenced image is available on the cloud storage and has a valid file name including an extension.

string localFileName = "output.doc";
string remoteFileName = "output.doc";
string localDataFileName = "data.xml";
string remoteDataFileName = "data.xml";
string remoteFolder = "Temp";
string localFolder = @"C:\Users\hp 840 g3\Downloads\AsposeError";
//string localDataFile = File.ReadAllText(localFolder + "/data.xml");

//upload Data File
var localDataFullName = Path.Combine(localFolder, localDataFileName);
var fullNameData = Path.Combine(remoteFolder, remoteDataFileName);
var requestDataUpload = new Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest(System.IO.File.OpenRead(localDataFullName), fullNameData);
await wordsApi.UploadFile(requestDataUpload);

//upload Template
var localFullName = Path.Combine(localFolder, localFileName);
var fullName = Path.Combine(remoteFolder, remoteFileName);
var requestTemplateUpload = new Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest(System.IO.File.OpenRead(localFullName), fullName);
await wordsApi.UploadFile(requestTemplateUpload);

var request = new ExecuteMailMergeRequest(
name: remoteFileName,
mailMergeDataFile: remoteFolder + "/" + remoteDataFileName,
//data: localDataFile,
folder: remoteFolder,
withRegions: false, 
cleanup: "UnusedFields",
useWholeParagraphAsRegion: false,
destFileName: "Temp/MailMerge.doc"
);

await wordsApi.ExecuteMailMerge(request);

Hi.

Thanks for the code. We will look into it.

We found the reason why you cannot find the image : there is a expiration on any object into the azure storage. After one day, any file is deleted.
This should not cause the our problem, since the upload is immediatly before the mailmerge.
The nane of the image is the right one. We can confirm it when we run in debug,

@Qc050.ETI

You may please upload a sample template and data file to your storage now and share the file names with me. I will again try to replicate the issue and investigate it.

data.zip (66.4 KB)

With this example, all files are in storage.

1 Like

@Qc050.ETI

Thanks for sharing the actual documents and these are working fine as expected. So please upgrade to the latest version of Aspose.Words Cloud SDK for .NET 22.1. It will resolve the issue. Please check the output documentMailMerge.zip (66.1 KB)
in the Temp folder.

Hi Tilal.
The latest sdk version won’t work for now. All call are now async and we have to change many things on our side. We did it but we could’nt save the pdf on our side anymore. We will be looking at it later.

We kept the 21.10 version and we fix the issue looking a the code sample that you send us.
We initially assign the data value with the data from filemergedata. Since your latest upgrade that seams to be breaking. setting this line in comments fix our issue and we can now mailmerge again
// data: File.ReadAllText(fileMergeData),

Thanks.

1 Like

@Qc050.ETI

Yes, now all API calls are asynchronous in the latest Aspose.Words Cloud SDK for .NET. Please let us know if you need any help in this regard.

You need to use any one of the parameters mailMergeDataFile and data. The mailMergeDataFile parameter is used to read mail merge data file from the cloud storage and the data parameter is used to get mail merge data from a local file.