TIFFのフレームデータ保存時、ランタイムエラーが発生する

TIFFファイルを読み込み、フレームデータを保存時もしくはJPEG保存を行うと、しばらくするとランタイムエラーが発生し、オンライン処理が停止してしまいます。Aspose.Imaging.DisposableObject.Finalize()での処理エラーとなっていますので、オブジェクト解放時に適切な処理を行っていないためだと考えています。

[環境]
・Aspose.Imaging for .NET ver.22.9.0
・ASP.NET Core(.NET6) on IIS

[発生エラー(イベントログ)]
Application: w3wp.exe
.NET Version: 6.0.8
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException: Safe handle has been closed.
Object name: ‘SafeHandle’.
at System.Threading.WaitHandle.WaitOneNoCheck(Int32 millisecondsTimeout)
at .()
at .Clear()
at .()
at .ReleaseUnmanagedResources()
at Aspose.Imaging.DisposableObject.(Boolean )
at Aspose.Imaging.DisposableObject.Finalize()

[ソースサンプル]
string picPath = “test.tiff”;

TiffImage mTiff = (TiffImage)Aspose.Imaging.Image.Load(picPath);
foreach (TiffFrame f in mTiff.Frames)
{
MemoryStream ms = new();
f.Save(ms, f.FrameOptions); or f.Save(ms, new JpegOptions());
}

こんにちは @Kazuyaamishima.
私たちはこの状況をシミュレートしようとします、そして、私たちはあなたに答えます。

@KazumiSameshima, フィードバックのおかげで、我々は同様のバグを再現することができました。 私たちはできるだけ早くそれを修正します。

I believe I am also experiencing this issue. I can make it happen in a console application by setting <ServerGarbageCollection>true</ServerGarbageCollection> in my project file.

Has a fix been released? Is there an ETA?

@CorvelAspose, issue IMAGINGNET-5819 planned to be fixed in Aspose.Imaging 22.12 release.

Is it possible to get an early build containing the fix? At minimum, I need to confirm that my issue will be fixed by the resolution. Ideally, I would like to go to production with it until the actual release, with the understanding that it may not be fully supported.

@CorvelAspose, Release 22.12 planned on Dec 1-5. Unfortunately we do not have complete solution for your issue yet, but we expect it to be done by Dec release. If you ask about hot-fix for you, unfortunately it also will take few weeks with issue fix and release preparation, so it also will be in first dates of Dec as regular 22.12 release we expect to provide.

Alright, sounds good. Thanks for the info!

Thanks, we will try to make 22.12 release as soon as possible regarding to expected release dates Dec 1-5.

I did some additional testing and found that a project using Aspose.Pdf without using Aspose.Imaging also has this problem.

Strangely, the stack trace still includes types in the Aspose.Imaging namespace, even though Aspose.Imaging.dll is not present in the test project’s build directory.

[Exception] System.Private.CoreLib.dll!System.Runtime.InteropServices.SafeHandle.DangerousAddRef(ref bool success)
[Exception] System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOneNoCheck(int millisecondsTimeout)
[Exception] Aspose.Imaging!   .()
[Exception] Aspose.Imaging!   <, >.Clear()
[Exception] Aspose.Imaging!   .()
[Exception] Aspose.Imaging!   .ReleaseUnmanagedResources()
[Exception] Aspose.Imaging!Aspose.Imaging.DisposableObject.(bool )
[Exception] Aspose.Imaging!Aspose.Imaging.DisposableObject.~DisposableObject()
Aspose.Imaging!   .()
Aspose.Imaging!   .ReleaseUnmanagedResources()
Aspose.Imaging!Aspose.Imaging.DisposableObject.(bool )
Aspose.Imaging!Aspose.Imaging.DisposableObject.~DisposableObject()

I would also like to point out that our company paid quite a bit of money to be able to use these libraries, and yet this common scenario of server GC is failing. This defect is impacting our project timeline. Is it possible to prioritize this issue from “try to do it” to “will be done”? We are very worried that the fix will slip to the next release.

@CorvelAspose, your ticket IMAGINGNET-5819 was prioritized and has been already fixed and will be included in Aspose.Imaging 22.12 release.Related to question for Aspose.Pdf you can ask in related forum Aspose.PDF Product Family - Free Support Forum - aspose.com

@KazumiSameshima , 您能否向我们提供您的示例 tiff 文件 test.tiff 以检查在修复您的文件后该问题没有重现? 谢谢。

@CorvelAspose, can you please provide your sample code and image file that you use with option ServerGarbageCollection true, we want to ensure that our fix works ok also with your exact example? Thanks.

Here you go:
Corvel.Transforms.ConsoleTest.7z (111.1 KB)

@CorvelAspose, as we see this is example related to Aspose.Pdf library only, but not Aspose.Imaging. It is another library. Do you have example to reproduce your issue with Aspose.Imaging library?

Apologies, I do not have a failing example for this library at this time. I was confused by the stack trace coming from Aspose.Pdf matching the stack trace in the first post of this thread.

I did try creating a test app that converts PNG to TIFF repeatedly in a single thread, but it doesn’t exhibit this problem.

@CorvelAspose, understood. We also can not reproduce in our library Aspose.Imaging issue with set up option ServerGarbageCollection. Please note, that if you need issue with Aspose.Pdf library from your example to be fixed, you need to ask it in forum branch related to Aspose.Pdf Aspose.PDF Product Family - Free Support Forum - aspose.com

I asked about it here. Thanks for the help!

You are welcome. Hope your issue will be solved fast.