.NET: A specific PNG file cannot be loaded -> error "Cannot open an image. The image file format may be not supported at the moment."

We are attempting to use the Aspose.Imaging .NET library to set XMP metadata in PNG files. This generally works as expected for most files. We’ve encountered a file that cannot be loaded without the library throwing an exception.

Affected file: Aprimo DAM.png

Stack trace:

at AsposeImaging.Image…(StreamContainer , LoadOptions )
— End of inner exception stack trace —
at AsposeImaging.Image…(StreamContainer , LoadOptions )

Code:

using (var inputStream = System.IO.File.OpenRead(localInputPath))
using (var img = Image.Load(inputStream))
{
XmpPacketWrapper xmp = ((RasterImage)img).XmpData;
if (xmp == null)
{
XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString());
XmpTrailerPi xmpTrailer = new XmpTrailerPi(true);
XmpMeta xmpMeta = new XmpMeta();
xmp = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
((RasterImage)img).XmpData = xmp;
}
if (xmp.ContainsPackage(“dc”))
{
foreach (var xmpPackage in xmp.Packages)
{
if (xmpPackage.NamespaceUri.Trim().ToLower() == “http:// purl.org/dc/elements/1.1/”)
{
if (xmpPackage.ContainsKey(“dc:keywords”))
{
xmpPackage[“dc:keywords”] = “2021”;
}
else
{
xmpPackage.AddValue(“dc:keywords”, “2021”);
}
}
}
}
else
{
XmpBasicPackage xmpPackage = new XmpBasicPackage(“dc”, “http:// purl.org/dc/elements/1.1/”);
xmpPackage .AddValue(“dc:keywords”, “2021”);
xmp.AddPackage(xmpPackage );
}
using (var outputStream = new MemoryStream())
{
img.Save(outputStream);
using (var fileStream = System.IO.File.Create(localOutputPath))
{
outputStream.Seek(0, System.IO.SeekOrigin.Begin);
outputStream.CopyTo(fileStream);
}
}
}

It fails on using (var img = Image.Load(inputStream))

@amytant, We checked your file, but could not load it using any other image viewers (infraview, acdsee, faststone, windows embedded viewer, photoshop, xnview, microsoft office picture manager, mspaint). Please provide for us how can we check it, or it looks broken.