user366312
user366312

Reputation: 16998

Why is this exception is being generated while running an OpenBabel hello-world program?

I am trying to compile and run the following OpenBabel test program supplied on their web page in 64bit mode.

Program.cs

using System;
using OpenBabel;

namespace MyConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                OBConversion obconv = new OBConversion();
                obconv.SetInFormat("smi");
                OBMol mol = new OBMol();
                obconv.ReadString(mol, "CCC");
                System.Console.WriteLine(mol.GetMolWt());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}

Expected Output:

44.09562

OpenBabel has two different installers for 32bit and 64bit modes on a PC.

I am getting the following message while running the source code in 32bit mode:

enter image description here

I get the following exception while running the source code in 64bit mode:

System.TypeInitializationException: The type initializer for 'OpenBabel.openbabel_csharpPINVOKE' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.
 ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
   at OpenBabel.openbabel_csharpPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_openbabel_csharp(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
   at OpenBabel.openbabel_csharpPINVOKE.SWIGExceptionHelper..cctor()
   --- End of inner exception stack trace ---
   at OpenBabel.openbabel_csharpPINVOKE.SWIGExceptionHelper..ctor()
   at OpenBabel.openbabel_csharpPINVOKE..cctor()
   --- End of inner exception stack trace ---
   at OpenBabel.openbabel_csharpPINVOKE.new_OBConversion__SWIG_2()
   at OpenBabel.OBConversion..ctor()
   at MyConsoleApplication.Program.Main(String[] args) in C:\Users\pc\source\repos\Openbabel__test\Program.cs:line 12

C:\Users\pc\source\repos\Openbabel__test\bin\Debug\net5.0\Openbabel__test.exe (process 12664) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

How can I resolve these errors/exceptions?

Upvotes: 3

Views: 183

Answers (0)

Related Questions