Help with .NET installation of OrTools from binary

1,526 views
Skip to first unread message

collin bhojwani

unread,
Jul 25, 2019, 2:21:39 PM7/25/19
to or-tools-discuss
Hello,

I need some help getting OrTools into my .NET C# project. I have followed the instructions to install from binary but I am not sure what to do next. I see that there are nuget packages in the binary installation, however when I add them via nuget package and reference them to my project I get one of the following errors:

When using the "Google.OrTools" package reference:
System.BadImageFormatException: 'Could not load file or assembly 'Google.OrTools, Version=7.2.6977.0, Culture=neutral, PublicKeyToken=77370d3086a71853' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)'

When using the "Google.OrTools.runtime.win-x64" package reference:
"System.TypeInitializationException: 'The type initializer for 'Google.OrTools.LinearSolver.operations_research_linear_solverPINVOKE' threw an exception.'"

Inner exceptions:
  1. TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception
  2. DllNotFoundException: Unable to load DLL 'Google.OrTools.runtime.win-x64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)


I was able to successfully run tools\make test_dotnet in the directory that I unpacked the binary. The instructions stop here however, and I'm a little lost on how to proceed. Any help would be appreciated. 

Thanks.


Laurent Perron

unread,
Jul 25, 2019, 3:17:23 PM7/25/19
to or-tools-discuss
you should use the Google.OrTools package.

Can you try using AnyCPU ?


Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/aaaa1f47-4d5c-42fd-8cfa-8ab41abb564e%40googlegroups.com.

collin bhojwani

unread,
Jul 25, 2019, 3:26:54 PM7/25/19
to or-tools-discuss
I am using AnyCPU in Visual Studio 2017. I am still getting the BadImageFormatException when using the Google.OrTools package. 

For clarification the process I followed is: 
  1. I unpack the binary download into my solution folder,
  2. Use Nuget package manager to install the Google.OrTools Nuget package that was in the binary unpack.
  3. Add reference to the Google.OrTools.dll that is now in the solution\packages folder
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools...@googlegroups.com.

Laurent Perron

unread,
Jul 25, 2019, 4:25:49 PM7/25/19
to or-tools-discuss
And if you get ortools directly from nuget?

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/dc7f4fe7-9462-415c-9871-c757003f5960%40googlegroups.com.

collin bhojwani

unread,
Jul 26, 2019, 10:17:19 AM7/26/19
to or-tools-discuss
If I get ORTools directly from NuGet I still get the same BadImage Exception:

System.BadImageFormatException
  HResult=0x80131058
  Message=Could not load file or assembly 'Google.OrTools, Version=7.2.6977.0, Culture=neutral, PublicKeyToken=77370d3086a71853' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
  Source=CBTest
  StackTrace:
   at CBTest.ORTest.Run() in C:\alm\CBTest\ORTest.cs:line 39
   at CBTest.Program.TestORtools() in C:\alm\CBTest\Program.cs:line 42
   at CBTest.Program.Main(String[] args) in C:\alm\CBTest\Program.cs:line 20

Inner Exception 1:
BadImageFormatException: Cannot load a reference assembly for execution.

Michael W Powell

unread,
Jul 26, 2019, 12:28:02 PM7/26/19
to or-tools-discuss


On Thursday, July 25, 2019 at 3:26:54 PM UTC-4, collin bhojwani wrote:
I am using AnyCPU in Visual Studio 2017. I am still getting the BadImageFormatException when using the Google.OrTools package. 

As far as I know, Google.OrTools is a 64-bit only image, so make sure your project(s) are all 64-bit.

There have also been OP's concerning internal 32-bit builds if you search the forums if that is desired.

Good luck!
Reply all
Reply to author
Forward
0 new messages