Issue with Aspose.Page using BinaryFormatter

We’re getting this error with the latest version of Aspose.Page (23.4.0):

System.AggregateException: One or more errors occurred. (BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.)
 ---> System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at #=zt6bNouLIa4ynXRWzr0Obe7NXkEicpptO0HTzm80_9xJf.#=zyZQccVCZWMABRwYQZUr9v14=(Boolean #=zf9yE6mI=)
   at #=z$s8HK5LQDCVWpy01gNADPpzTjBYcoj$C_7maqhUzTvbI.#=zzYU40SpaSs$C(#=z66fwF6mwGvQDZcKuEtcq9LFDN5wrr22mmhsIbGJosrc3 #=zZ9wTeWU=, Int64 #=zeELty3U=)
   at #=z66fwF6mwGvQDZcKuEtcq9LFDN5wrr22mmhsIbGJosrc3.#=zKGaFaNs=(#=z$s8HK5LQDCVWpy01gNADPpzTjBYcoj$C_7maqhUzTvbI #=zyHuK_v4=)
   at #=zzHPRV0q$6cQW530rTWO8aWx9lVOD4fORBubdtzg=.#=zOc_jv3U=(#=z66fwF6mwGvQDZcKuEtcq9LFDN5wrr22mmhsIbGJosrc3 #=zZ9wTeWU=)
   at #=zqhNXclJtEldhyOE6_hjs4Hs8P9C8YK1_wXq0RLKFDIA7.#=zRCgLs8CI8lS4(#=z66fwF6mwGvQDZcKuEtcq9LFDN5wrr22mmhsIbGJosrc3 #=zZ9wTeWU=)
   at #=zIJ4HQ2rDGrYoOd3d7qzEYfabClm0Wj55MmthASo=.#=z_WQfS$4=(Boolean #=zPuhHs7w=)
   at #=zIJ4HQ2rDGrYoOd3d7qzEYfabClm0Wj55MmthASo=.#=z3J5WvII=()
   at #=zIJ4HQ2rDGrYoOd3d7qzEYfabClm0Wj55MmthASo=.#=zmjhMReo=(Boolean #=zNGpdtu$KtSW2)
   at Aspose.Page.EPS.PsDocument.#=z2lzVMQIJElxf(SaveOptions #=z8vg0FQA=, Device #=zWqj40kI=)
   at Aspose.Page.EPS.PsDocument.#=zHyW5Hzg=(SaveOptions #=z8vg0FQA=, Device #=zWqj40kI=)
   at Aspose.Page.EPS.PsDocument.Save(Device device, SaveOptions options)

@rafaeloliveira

Can you please share the sample code snippet as well as sample files for our reference? So that we can test the scenario in our environment and address it accordingly.

Sure, here’s an example:
support_solid.7z (369.2 KB)

But this is happening for any eps file I’ve tested so far.

@rafaeloliveira

Thanks for sharing the sample file. Can you please share the sample code snippet as well that you are using?

The main issue is that Aspose.Page is using BinaryFormatter at all - this has been deprecated by Microsoft since a long time, and is a security issue: Deserialization risks in use of BinaryFormatter and related types - .NET | Microsoft Learn

The code is simply trying to save the .eps file as a pdf:

    var document = new Aspose.Page.EPS.PsDocument(stream);

    var pdfStream = new MemoryStream();

    var options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions()
    {
        JpegQualityLevel = 100,
        ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg,
        TextCompression  = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate,
        SupressErrors = true,
    };

    Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream);

    document.Save(device, options);

@rafaeloliveira

Can you please try using the latest version of the API as we used it in our environment and could not replicate the issue that you mentioned.

Hi @asad.ali, I would love to try it, but the latest version of Aspose.Page has also the wrong dependencies for net7.0:

NuGet Gallery | Aspose.Page 23.9.0

Which blocks it from being used on Linux and macOS (which need System.Drawing.Common >= 6.0.0).

If you can release a version with the right dependency constraint, happy to test if the issue still happens.

@rafaeloliveira

It is logical to use System.Drawing 6.0 with .NET 6.0 and System.Drawing 7.0 with .NET 7.0. If your project is targeted to .NET 6.0 and you install Aspose.Page using NuGet Package manager, System.Drawing 6.0 will be installed.

@asad.ali The issue is still happening on the latest version of Aspose.Page

[fail] [2024-07-25 10:33:12] Failed to process file PcUcg5PvboALvwQnj8WhQq ./sample-files/Home santa.eps
System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See Deserialization risks in use of BinaryFormatter and related types - .NET | Microsoft Learn for more in> at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) at #=zhvmQjMRR2b$WfMu3VZaaa50ZZ1pQSaiRLZn0jdQa886R.#=zn_Zu9yIABxzG3opzgiTirdI=(Boolean #=zpg7JWKk=) at #=zbafr2Y3zuQoneYf$G3RCwR6AYv6rPLyNEeXN8xRrFdwL.#=zC6Zdbjag10Cz(#=zcK93mIGCA8i3X3UuNJGrTO6ZN90_J8uwGWkF5$U8BTPk #=zR2$oOkg=, Int64 #=zG9YiYnc=)
at #=zcK93mIGCA8i3X3UuNJGrTO6ZN90_J8uwGWkF5$U8BTPk.#=zb2ks9R4=(#=zbafr2Y3zuQoneYf$G3RCwR6AYv6rPLyNEeXN8xRrFdwL #=zbxmwg5s=)
at #=zJ2iXPC1Zk8488RpipIOEUu69NGVL2H30DV1qsYA=.#=zHDYacOs=(#=zcK93mIGCA8i3X3UuNJGrTO6ZN90_J8uwGWkF5$U8BTPk #=zR2$oOkg=)
at #=zs0apdLIenx7OgyZc637jMNX2plVnFUF5trnrM2zsLPRe.#=zPKL7tyiKdmay(#=zcK93mIGCA8i3X3UuNJGrTO6ZN90_J8uwGWkF5$U8BTPk #=zR2$oOkg=)
at #=zuR$BcI_zMxNFl464wM57g0hZfEMoKftUOFyLhck=.#=zLukDkBs=(Boolean #=zakHg5hg=) at #=zuR$BcI_zMxNFl464wM57g0hZfEMoKftUOFyLhck=.#=zqA3Oeu8=()
at #=zuR$BcI_zMxNFl464wM57g0hZfEMoKftUOFyLhck=.#=zupWP$iM=(Boolean #=z3EVosNCtrHJL)
at Aspose.Page.EPS.PsDocument.#=z2vd4LJSWybW5(SaveOptions #=zMUJYZUg=, #=zZNQlf8Qg2MM72QSEvg== #=z0Nf7u5M=)
at Aspose.Page.EPS.PsDocument.#=zkxCz3Iw=(SaveOptions #=zMUJYZUg=, #=zZNQlf8Qg2MM72QSEvg== #=z0Nf7u5M=)
at Aspose.Page.EPS.PsDocument.#=zb2ks9R4=(#=zZNQlf8Qg2MM72QSEvg== #=z0Nf7u5M=, SaveOptions #=zMUJYZUg=) at Aspose.Page.EPS.PsDocument.SaveAsPdf(Stream pdfStream, PdfSaveOptions options)
at Mosaik.Extractors.PostScriptExtractor.DoProcess(Stream stream, CancellationToken token)

A sample file triggering the issue is attached

Home santa.zip (353.9 KB)

@rafaeloliveira

With 24.7 and .NET Core 6.0, we could not notice any exception in our environment. Below is the used code sample and the obtained output PDF:

var document = new Aspose.Page.EPS.PsDocument(dataDir + "Home santa.eps");

var pdfStream = new MemoryStream();

var options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions()
{
    JpegQualityLevel = 100,
    ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg,
    TextCompression = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate,
    SupressErrors = true,
};

Aspose.Page.EPS.Device.PdfSaveOptions device = new Aspose.Page.EPS.Device.PdfSaveOptions(false);

document.SaveAsPdf(dataDir + "output.pdf", device);

output.pdf (101.7 KB)