Page 1 of 1

CADtoDWG.SaveAsDWG -> Exception Error

Posted: 26 Jan 2024, 18:36
by Wahid Massan
I have written a small amount of test code to simply open a DWG file and then save it - Essentially making a copy. I wanted to ensure that I am not causing any issue by editting the file, so it's very simple:

Code: Select all

        void SaveFile()
        {
            CADImage cadImage = CADImage.CreateImageByExtension(selectFile.FileName);
            cadImage.LoadFromFile(selectFile.FileName);
            CADtoDWG.SaveAsDWG(cadImage, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "output.dwg"));
        }
I am using .NET (version 8.0) windows forms with CAD.NET 15.0.0.57290.

When I call this function, the following error is presented:
The type initializer for 'CADImport.Export.CADExportFrame' threw an exception.
It's a shame, because the library has some great tools - But I cannot save the file. Is there a known issue around saving .DWG files?

Re: CADtoDWG.SaveAsDWG -> Exception Error

Posted: 30 Jan 2024, 14:00
by support
Wahid Massan wrote:
26 Jan 2024, 18:36
I have written a small amount of test code to simply open a DWG file and then save it - Essentially making a copy. I wanted to ensure that I am not causing any issue by editting the file, so it's very simple:

Code: Select all

        void SaveFile()
        {
            CADImage cadImage = CADImage.CreateImageByExtension(selectFile.FileName);
            cadImage.LoadFromFile(selectFile.FileName);
            CADtoDWG.SaveAsDWG(cadImage, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "output.dwg"));
        }
I am using .NET (version 8.0) windows forms with CAD.NET 15.0.0.57290.

When I call this function, the following error is presented:
The type initializer for 'CADImport.Export.CADExportFrame' threw an exception.
It's a shame, because the library has some great tools - But I cannot save the file. Is there a known issue around saving .DWG files?
Hi,
Unfortunately, this information is not enough to help you out, we need more details on the error. Is Cadimage null? What is your file extension? Does the external sgcadexp.dll library lie in the execution folder?
Please, try saving selected file in the Editor_NetCore demo. By the way, we released a newer CAD .NET version, that is available at https://cadsofttools.com/company/news/c ... -released/.
Also, I'd like to note that if an input file is raster then it will be saved as a raster image (not CADImage).

Best wishes,
Catherine.