Aspose.CAD.Image threw an exception

I am having this error when loading a DWG to an aspose image. The code i have works on our other website. Below is the error message.

System.TypeInitializationException: The type initializer for \u0027Aspose.CAD.Image\u0027 threw an exception. —\u003e
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Retrieve the LoaderExceptions property for more information.\r\n at
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)\r\n
at System.Reflection.Assembly.GetTypes()\r\n at Aspose.CAD.Image…cctor()\r\n — End of inner exception stack trace
—\r\n at Aspose.CAD.Image.Load(String filePath)\r\n

The error you are encountering, System.TypeInitializationException, typically indicates that there is an issue with loading the necessary types or assemblies required by the Aspose.CAD library. This can happen for several reasons, including:

  1. Missing Dependencies: Ensure that all required dependencies for Aspose.CAD are correctly referenced in your project. Sometimes, a missing or incompatible version of a dependency can lead to this error.

  2. Incompatible Framework: Verify that your project is targeting a compatible version of the .NET framework that is supported by the version of Aspose.CAD you are using.

  3. Corrupted Installation: If the library was not installed correctly, it might lead to such exceptions. Try reinstalling the Aspose.CAD library to ensure that all files are intact.

  4. LoaderExceptions Property: The error message suggests retrieving the LoaderExceptions property for more information. This property can provide specific details about which types could not be loaded, which can help in diagnosing the issue.

Here’s a sample code snippet to load a DWG file using Aspose.CAD, which you can use to verify your implementation:

using Aspose.CAD;
using Aspose.CAD.ImageOptions;

// Load the DWG file
string filePath = "path/to/your/file.dwg";
using (var image = Image.Load(filePath))
{
    // Set rasterization options
    var rasterizationOptions = new CadRasterizationOptions();
    rasterizationOptions.PageWidth = 1600;
    rasterizationOptions.PageHeight = 1200;

    // Save as an image
    image.Save("output.png", new PngOptions { RasterizationOptions = rasterizationOptions });
}

Make sure to replace "path/to/your/file.dwg" with the actual path to your DWG file. If the problem persists after checking these points, consider reaching out to Aspose support for further assistance.

Can you provide me the list of dependecies for Aspose.CAD?
The framework that i am using is .NET Framework 4.8, is there a conflict here?

@EricAce,
please provide the details of the exception stored in LoaderExceptions as per “Retrieve the LoaderExceptions property for more information.” message. Here is other thread about the same issue - The type initializer for 'Aspose.CAD.Image' threw an exception, please review it.