Free Support Forum -

Aspose.Word MailMerge with Image

Hello there,
I’m trying to mailMerge an Image into a document. I already read about the IFieldMergingCallback-Interface and also already implemented it.

What I want to do. I get a list of fields and a list of values from Json and I deserialize them into arrays. The value List does contain Images as Base64-Strings sometimes. I take those Strings and Convert them into Images - This is no problem. I already tested it with hard values and also the merge is working.

My Problem:
args.FieldValue is null during the IFieldMergingCallback.ImageFieldMerging-Event and I don’t know why…

The class which is implementing the Interface:

void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e) {
    //This is always null    
    if (e.FieldValue != null) {
        byte[] imageBytes = Convert.FromBase64String(e.FieldValue.ToString());
        using (var ms = new MemoryStream(imageBytes)) {
            ms.Position = 0;
            e.Image = Image.FromStream(ms, true, true);

My Main-Class:

string[] fieldList = JsonConvert.DeserializeObject<string[]>(fieldJson);
object[] valueList = JsonConvert.DeserializeObject<object[]>(valueJson);

HandleMergeImageField hmif = new HandleMergeImageField();

//For Mailmerging Images
doc.MailMerge.FieldMergingCallback = hmif;

//Execute MailMerge for field- and valueList
doc.MailMerge.Execute(fieldList, valueList);

Thank you for your help and best regards,


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hello tahir,
thanks for your quick reply.
Unfortunately if encountered my own stupidity. If resolved the issue by renaming the field-tag in the fieldList from “Image:ImageMergeField” to “ImageMergeField” and voilá it works as aspected.



Thanks for your feedback. Yes, you need to insert mail merge field as Image:MyFieldName into document. It is nice to hear from you that your problem has been solved.