"IOException: An unexpected network error occurred." Exceptions

I am testing combining many TIFs and for the most part I’m using sample code. During most of my tests I get an Aspose.Imaging.CoreExceptions.ImageSaveException exception with an inner exception of IOException: An unexpected network error occurred. These are being thrown on calls to Aspose.Imaging.Image.Save() and I’ve also seen it on calls to (TiffImage)Image.Load().

The source of my TIFFs is on our network as is the merged TIFF destination. I am merging a lot of TIFFs and I suppose the error is related to maybe network drops or something, but I wonder though because similar tests with other toolkits aren’t seeing this problem.

Any ideas?

Thank you
-Jay

@JayRi, Please provide for us sample code and files that you try to test.

Thank you for your attention Samir

I can’t provide the files I’m using because they’re confidential, but basically I’m attempting to merge a folder full of TIF files, there are 230 of them with a total of 1 GB in size. These are multipage TIFs, no oversized pages. Almost all Group4 compression with a few JPEG compressed. Note the errors have never happened on a specific file, they seem to randomly occur.

The code is below:
sourceFolderFullname is a folder with the tiffs we’ll merge
mergeFileFullname is the full name of the merged file

private void Merge(string sourceFolderFullname, string mergeFileFullname) {

	var sourceFiles = Directory.GetFiles(sourceFolderFullname, "*.tif");

	// Create a new image by passing the TiffOptions and size of first frame, we will remove the first frame at the end, cause it will be empty
	TiffImage output = null;
	List<TiffImage> images = new List<TiffImage>();

	foreach (var file in sourceFiles) {
		// Create an instance of TiffImage and load the source image
		TiffImage input = (TiffImage)Image.Load(file);    // Exceptions here somtimes
		images.Add(input); // Do not dispose before data is fetched. Data is fetched on 'Save' later.
		foreach (var frame in input.Frames) {
			if (output == null) {
				// Create a new tiff image with first frame defined.
				output = new TiffImage(TiffFrame.CopyFrame(frame));
			} else {
				// Add copied frame to destination image
				output.AddFrame(TiffFrame.CopyFrame(frame));
			}
		}
	}

	if (output != null) {
		using (var fs = new FileStream(mergeFileFullname, FileMode.CreateNew)) {
			// Save the result
			output.Save(fs);      // Exceptions here somtimes
		}
	}
}

I’ve seen exceptions in a couple spots in the code, I’ve labelled these with “// Exceptions here somtimes” comments.

I believe these are the only two exceptions I’ve seen:

Aspose.Imaging.CoreExceptions.ImageLoadException: Image loading failed. ---> Aspose.Imaging.CoreExceptions.ImageLoadException: Unable to read file. Exception: An unexpected network error occurred.

System.IO.IOException: An unexpected network error occurred.

It’s entirely possible this problem is network related on my end. If so any suggestions on making the code a bit more fault tolerant to prevent these exceptions? I suppose I can try … catch them and repeat a failed call.

Any other ideas?

Thanks again

@JayRi, Looking to your exception stack it looks that error related to network on your side. Unfortunately, we can not do nothing for this, but to overcome this, you can initially download all your images to your local machine to make local cache (or download image by image and than save to resulting tiff image). This will work slower by you, but you will be able to make sure that images downloaded and may be processed. Also, you may create your resulting tiff file using Image.Create(), here is sample code for this Working with multipage image formats|Documentation