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

Free Support Forum - aspose.com

Mail merge engine crashes for image stream using .NET


below is the mail merge callback method:
public void ImageFieldMerging(ImageFieldMergingArgs args)

When the mail merge callback method gets called to dynamic set an image

we assign the image as follows

args.ImageStream = myImageStream;

The issue is that aspose closes the stream after the merge, so I have to create new stream every time.

But I have a requirement that I use the same logo on all dynamic pages, so for
performance, I want to cache my image streams.

Is there a way to do this?


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 will start investigation into your issue and provide you more information. Thanks for your cooperation.

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


What I am saying is that I have cached the logo in my class as follows.
public class HandleMergeImageField : IFieldMergingCallback
private MemoryStream LogoImage;

public HandleMergeImage()
byte[] bytes = File.ReadAllBytes(imageFilepath);
LogoImage = new MemoryStream(bytes);

public void ImageFieldMerging(ImageFieldMergingArgs args)
if ((args.FieldValue == null) ||

	MemoryStream imageStream = null;

	if (args.FieldName.Equals("Logo"))
		args.ImageStream = LogoImage;



The first time merge image is called - all is ok,
but 2nd time it crashes because error says the stream was closed

Please declare this variable at global level to avoid this exception.

If you still face problem, please share the requested resources in my previous post for testing.