3

我正在尝试以64 位模式编译并运行其网页上提供的以下 OpenBabel 测试程序。

程序.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);
            }
        }
    }
}

预期输出:

44.09562

OpenBabel 有两个不同的安装程序,用于 PC 上的 32 位和 64 位模式。

在 32 位模式下运行源代码时,我收到以下消息:

在此处输入图像描述

在 64 位模式下运行源代码时出现以下异常:

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 . . .

如何解决这些错误/异常?

4

0 回答 0