Free Support Forum - aspose.com

Image loading failed at Aspose.CAD.Image.LoadImage() System.OutOfMemoryException

I am using aspose.cad(19.2.0) with Microsoft.Windows.Compatibility for PDF conversion using .Net Core 2.1. .

When looping and processing multiple dxf file one by one , the code is failing and giving following error :
Error Stack Trace-- at Aspose.CAD.Image.LoadImage(StreamContainer streamContainer, LoadOptions loadOptions)
Download Dwg Error–Image loading failed. Detail: System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at Aspose.CAD.StreamContainer.Save(Stream destinationStream, Int32 bufferSize, Int64 length)
at …ctor(Stream )
at . (Stream )
at .(Stream )
at .CanLoad(StreamContainer , LoadOptions )
at Aspose.CAD.ImageLoadersRegistry.GetFirstSupportedDescriptor(Stream stream, LoadOptions loadOptions, Boolean releaseSyncStream)
at Aspose.CAD.Image.LoadImage(StreamContainer streamContainer, LoadOptions loadOptions)

code snip: (few lines)

      using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(drawingPath))
        {
                // Create an instance of CadRasterizationOptions
                CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions
                {
                    // Set page width & height
                    PageWidth = 1500,
                    PageHeight = 1500,
                    ContentAsBitmap = true, 
                };

               if (onNames!=null)
                {
                  rasterizationOptions.Layers = onNames.ToArray();// layers to turn on.
                }

                 // Create an instance of PdfOptions
                 PdfOptions pdfOptions = new PdfOptions { VectorRasterizationOptions = rasterizationOptions };

image.Save(dwgStream, pdfOptions);

@dwgtest,

I have observed the issue shared by you and request you to please try using Aspose.CAD for .NET 20.1 on your end. In case the issue still persist then please share the source file reproducing the issue on your end.

I tried using .NET 20.1 before but is is giving duplicate drawings and is very slow.Almost taking double time to convert same dxf file.

I am sharing the sample code i tested with Aspose.cad .net 20.1.This is too slow and give twp pages of same drawing in pdf.

public void getPdf()
{
//Drawing PATH
string drawingPath = @“dimmy.dxf”;

        //LIST OF LAYERS TO BE TURN ON change it with your layers to be activated   *** 
        List<string> ActiveLayerNames = new List<string>();
        ActiveLayerNames.Add("WITHOUT-FREE-COOL");
        ActiveLayerNames.Add("WITHOUT-HGBP");
        ActiveLayerNames.Add("MFG2150P-P");
        ActiveLayerNames.Add("DIM-UNIT");
        ActiveLayerNames.Add("TITLEBLK"); 

        using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(drawingPath))
        {
            // Create an instance of CadRasterizationOptions
            CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions
            {
                // Set page width & height
                PageWidth = 1500,
                PageHeight = 1500,
                ContentAsBitmap = true,
            };

            // layers to turn on.***
            rasterizationOptions.Layers = ActiveLayerNames.ToArray();
       
         PdfOptions pdfOptions = new PdfOptions { VectorRasterizationOptions = rasterizationOptions };

            string filename = Guid.NewGuid().ToString() + ".pdf";
            image.Save(filename, pdfOptions);


        }
    }

@dwgtest,

I have observed the sample code shared and request you to please share the source file as well.

Source file use almost same code shared above. The code shared above failed mainly when we deploy it to Azure Environment (.net core)

Dose the Aspose.DLL works when deployed as web-app in Azure ?

Internal log from azure web app show following error :

Image loading failed. Detail: System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at Aspose.CAD.StreamContainer.Save(Stream destinationStream, Int32 bufferSize, Int64 length)
at � …ctor(Stream �)
at � .� �(Stream �)
at � .�(Stream �)
at � .CanLoad(StreamContainer �, LoadOptions �)
at Aspose.CAD.ImageLoadersRegistry.GetFirstSupportedDescriptor(Stream stream, LoadOptions loadOptions, Boolean releaseSyncStream)
at Aspose.CAD.Image.LoadImage(StreamContainer streamContainer, LoadOptions loadOptions)

@dwgtest,

There is no issue while using Aspose.CAD in Azure. The issue that you are facing is probably memory running out. I request you to please share the source file that you are using on your end to reproduce the issue.