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.