Thanks - very comprehensive. Hopefully this will be useful to point to for
future .NET users.

On 7 June 2018 at 01:06, Leif Peterson <leifepeter...@sbcglobal.net> wrote:

> RESOLVED.  I got .NET working by selecting “x64” in the Build option of
> .NET, because I originally installed the 64-bit version of the Windows
> GUI.  Basically, I learned that the following are required to get .NET
> working (C# or VB.NET) with the OBDotNet.dll assembly:
>
>
>
> 1). *Download* either the 32-bit (x86) or 64-bit (x64) version of the
> OpenBabel Windows GUI program and install, depending on what version of
> Windows 10 is installed on the machine (32-bit or 64-bit).
>
>
>
> 2). *Reference the .dll within the .NET Project:* Within the .NET
> Project, on the right panel under Solution Explorer, right-click on
> References, select Add ReferenceàBrowse, and then go to the folder:
>
>
>
> C:\Program Files\OpenBabel-2.4.1  (if 64-bit versions of Windows is being
> used.  FYI - version 2.4.1 of the 64-bit Windows GUI of OpenBabel was
> installed)
>
>
>
> C:\Program Files (x86)\OpenBabel-2.4.1  (if a 32-bit version of Windows is
> being. Users would need to install the 32-bit version of the Windows GUI of
> OpenBabel)
>
>
>
> Then, double-click on the file OBDotNet.dll, and the assembly will now be
> referenced inside the .NET project.
>
>
>
> 3). *Set the version of Windows to be used by the compiled project
> executable (projectname.exe): *Within .NET, select from the top menu
> ProjectàProjectName PropertiesàBuild, and set “Project target” to x64
> (for 64-bit) and x86 for 32-bit Windows.   Don’t use “Any CPU,” since this
> option is used when “Prefer 32-bit” is or is not checked.  This is a way to
> have the user’s Windows decide automatically whether your package should be
> installed in the 32-bit “C:\Program Files (x86)” folder or the 64-bit
> folder “C:\Program Files.  (To use OpenBabel’s .NET assembly, everything
> has to be married up regarding 32-bit or 64-bit, since there are two
> issues: (a) is 32-bit or 64-bit OpenBabel Windows GUI installed?, and (b)
> is the Windows 32-bit or 64-bit?  Thus, you don’t want your Windows or a
> user’s Windows that installs your distributed package deciding on its own
> what to do.
>
>
>
> 4). *Copy the OBDotNet.dll file* from folder C:\Program
> Files\OpenBabel-2.4.1  (where the 64-bit GUI program is installed) and
> paste into folder C:\...wherever the .NET project is …\OpenBabel\bin\Debug
> as well as C:\...wherever the .NET project is…\OpenBabel\bin\Release.
>
>
>
> 5). *Compile* the example code listed above, and the molecular weight of
> propane 44.0596 will appear in the popup-window.
>
>
>
> 6). *Run* the compiled executable file (assembly) by double-clicking
> OpenBabel.exe in folder \bin\Debug if the compile option was “Debug,” or in
> the \bin\Release folder if the “Release” option was used during compiling.
>
> The above should work for anyone experiencing the 
> 'OpenBabel.openbabel_csharpPINVOKE'
> error in windows when using .NET.   Usage of C# or VB.NET should not
> matter.   Obviously, use Visual Studio 2010, 2015, 2017, etc., and not
> Visual Studio 8 or earlier.   The Community version of VS is always free.
>
>
>
> -------------------------------------------
>
>
>
> *Sent:* Wednesday, June 6, 2018 8:49 AM
> *Subject:* Re: [Open Babel] Visual Studio 2015 C# Initialization
> Exception, .dll's are Obfuscated?
>
>
>
> We need more details to help diagnose the problem. The best place to do
> this is over in our issue tracker at http://github.com/openbabel/issues.
> We'll need to know exactly what you did step by step, starting with what
> exactly did you download, etc.
>
>
>
> The problem could be anything unfortunately. This error message is
> triggered by any mismatch of the .NET and native code. For example, you may
> have used the 32-bit .NET dll with the .64 bit native dll. You may have an
> old version of Open Babel installed, and there was a mismatch there. Etc,
> etc. If you can take us through the steps one by one, we should be able to
> get to the bottom of this.
>
>
>
> We don't obfuscate anything, at least not intentionally. If there's
> something amiss, let us know.
>
>
>
> -------------------------------------------
>
>
>
>
>
> On 4 June 2018 at 13:35
>
>
>
> I loaded all the .dlls in the executable folder, and also Reference the
> OBDotNet.dll in the VS 2015 (C#) within the project, and am getting an
> exception
>
>
>
> Additional information: The type initializer for 
> 'OpenBabel.openbabel_csharpPINVOKE'
> threw an exception.
>
>
>
> Example code is below:
>
>
>
> using System;
>
> using System.Collections.Generic;
>
> using SystemLinq;
>
> using System.Threading.Tasks;
>
> using System.Windows.Forms;
>
> using OpenBabel;
>
>
>
>
>
> namespace MyConsoleApplication
>
> {
>
>     class Program
>
>     {
>
>         static void Main(string[] args)
>
>         {
>
>             OBConversion obconv = new OBConversion(); * //**ß** Exception
> thrown here*
>
>             obconv.SetInFormat("smi");
>
>             OBMol mol = new OBMol();
>
>             obconv.ReadString(mol, "CCC");
>
>             double mowwt = mol.GetMolWt();
>
>             var smowwt = mowwt.ToString();
>
>             MessageBox.Show(smowwt);
>
>         }
>
>     }
>
> }
>
>
>
> 2.       It seems that the .dlls are obfuscated as well, so how open is
> OpenBabel?
>
>
>
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to