I load dwg file using below sample code with latest dll.
private void button1_Click(object sender, EventArgs e)
{
// load DWG in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load(“E:\CAD file\S01_INDEX.dwg”))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of PdfOptions
var options = new Aspose.CAD.ImageOptions.PdfOptions();
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export DWG to PDF
image.Save("E:\\CAD file\\output.pdf", options);
}
The error you’re encountering when loading the DWG file with the latest Aspose.CAD DLL may be related to the structure of the DWG file itself. Certain sections required for proper loading or exporting might be missing or incompatible with the current version of the library.
Solution
To troubleshoot and resolve this issue, please follow these steps:
Check for Errors During Load: Utilize the LoadOptions class to check for any errors that occur during the loading of the DWG file. Set the IgnoreErrors property to true to bypass non-critical errors, but log any errors for further investigation.
Use LoadOptions: Modify your loading code to include LoadOptions and check for errors:
var loadOptions = new Aspose.CAD.LoadOptions();
loadOptions.IgnoreErrors = true; // Set to true to ignore non-critical errors
using (var image = Aspose.CAD.Image.Load("E:\\CAD file\\S01_INDEX.dwg", loadOptions))
{
// Proceed with your existing code
}
Check DWG File Compatibility: Ensure that the DWG file is compatible with the version of Aspose.CAD you are using. The library supports specific AutoCAD DWG revisions, so verify that your file matches one of the supported formats.
Inspect the DWG File: If possible, open the DWG file in AutoCAD or a similar application to check for any issues or corruption in the file.
Code
Here’s a modified version of your code that includes error handling:
private void button1_Click(object sender, EventArgs e)
{
var loadOptions = new Aspose.CAD.LoadOptions();
loadOptions.IgnoreErrors = true; // Ignore non-critical errors
using (var image = Aspose.CAD.Image.Load("E:\\CAD file\\S01_INDEX.dwg", loadOptions))
{
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
var options = new Aspose.CAD.ImageOptions.PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
image.Save("E:\\CAD file\\output.pdf", options);
}
}
Next Steps
Run the modified code to see if it resolves the issue.
If the problem persists, check the DWG file for compatibility or corruption.
If you continue to face issues, please provide any error messages or logs generated during the loading process for further assistance.
Same error come i try with load options the below is error message
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for ‘Aspose.CAD.Image’ threw an exception.
Source=Aspose.CAD
StackTrace:
at Aspose.CAD.Image.Load(String filePath, LoadOptions loadOptions)
at AspoeCADtest.Form1.button1_Click(Object sender, EventArgs e) in D:\AspoeCADtest\AspoeCADtest\Form1.cs:line 16
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Could not load file or assembly ‘MessagePack, Version=2.5.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be’. The system cannot find the file specified.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.