or-tools: NuGet osx-arm64 package broken

What version of OR-Tools and what language are you using? Version: 9.5.2237.0 Language: C#

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi) N/A

What operating system (Linux, Windows, …) and version? MacOS Ventura 13.5

What did you do? I have been trying to use OR-Tools in a C# .NET project, but when running there is always an error with loading a file/assembly. The error shows up even when trying to run the example project linked to in the install guide.

The example project gives the following error message:

pederlh@Peders-MacBook-Air:~/Repositories/dotnet_or-tools$ dotnet run -c release
/usr/local/share/dotnet/sdk/7.0.302/Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "/Users/pederlh/.nuget/packages/google.ortools/9.5.2237/lib/net6.0/Google.OrTools.dll", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. [/Users/pederlh/Repositories/dotnet_or-tools/project.csproj]
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Google.OrTools, Version=9.5.2237.0, Culture=neutral, PublicKeyToken=53dbb1ea090cbef7'. The system cannot find the file specified.

File name: 'Google.OrTools, Version=9.5.2237.0, Culture=neutral, PublicKeyToken=53dbb1ea090cbef7'

In addition, following the guide on building from source also leads to failure, and gives a similar error message

pederlh@Peders-MacBook-Air:~/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534$ make test
/Library/Developer/CommandLineTools/usr/bin/make run SOURCE=examples/3_jugs_regular/3_jugs_regular.cs
"/opt/homebrew/bin/dotnet" build examples/3_jugs_regular/project.csproj
MSBuild version 17.6.1+8ffc3fe3d for .NET
  Determining projects to restore...
/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj : warning NU1701: Package 'Google.OrTools 9.6.2534' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
  Restored /Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj (in 1,72 sec).
/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj : warning NU1701: Package 'Google.OrTools 9.6.2534' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project. [TargetFramework=netcoreapp3.1]
/usr/local/share/dotnet/sdk/7.0.302/Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "/Users/pederlh/.nuget/packages/google.ortools/9.6.2534/lib/net46/Google.OrTools.dll", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. [/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj::TargetFramework=netcoreapp3.1]
/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj : warning NU1701: Package 'Google.OrTools 9.6.2534' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project. [TargetFramework=net6.0]
/usr/local/share/dotnet/sdk/7.0.302/Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "/Users/pederlh/.nuget/packages/google.ortools/9.6.2534/lib/net6.0/Google.OrTools.dll", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. [/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj::TargetFramework=net6.0]
  project -> /Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/bin/Debug/netcoreapp3.1/Google.OrTools.3_jugs_regular.dll
  project -> /Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/bin/Debug/net6.0/Google.OrTools.3_jugs_regular.dll

Build succeeded.

/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj : warning NU1701: Package 'Google.OrTools 9.6.2534' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj : warning NU1701: Package 'Google.OrTools 9.6.2534' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project. [TargetFramework=netcoreapp3.1]
/usr/local/share/dotnet/sdk/7.0.302/Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "/Users/pederlh/.nuget/packages/google.ortools/9.6.2534/lib/net46/Google.OrTools.dll", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. [/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj::TargetFramework=netcoreapp3.1]
/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj : warning NU1701: Package 'Google.OrTools 9.6.2534' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project. [TargetFramework=net6.0]
/usr/local/share/dotnet/sdk/7.0.302/Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "/Users/pederlh/.nuget/packages/google.ortools/9.6.2534/lib/net6.0/Google.OrTools.dll", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. [/Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/project.csproj::TargetFramework=net6.0]
    5 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.13
"/opt/homebrew/bin/dotnet" run --no-build --framework net6.0 --project examples/3_jugs_regular/project.csproj --
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Google.OrTools, Version=9.6.2534.0, Culture=neutral, PublicKeyToken=37e4c4e778bf1216'. The system cannot find the file specified.

File name: 'Google.OrTools, Version=9.6.2534.0, Culture=neutral, PublicKeyToken=37e4c4e778bf1216'
   at ThreeJugsRegular.Solve(Int32 n)
   at ThreeJugsRegular.Main(String[] args) in /Users/pederlh/Repositories/or-tools_arm64_macOS-13.2.1_dotnet_v9.6.2534/examples/3_jugs_regular/3_jugs_regular.cs:line 278
make[1]: *** [run] Error 134

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 17

Most upvoted comments

I’m using macOS 13.5 (Venture) with an M2 Chip, and I’m working with Visual Studio 2022 and .NET 7. I also have Google OR-Tools version 9.7.2996 installed. I encountered an issue, but I managed to resolve it. Here are the steps I followed:

  1. Change your build settings from x64/x86 to Any CPU.

  2. On the server, within your app service, navigate to the “Configuration” settings. Under “General Settings,” locate the “Platform Setting” and switch it from 32-bit to 64-bit.

  3. If the issue still persists, you can manually check if a DLL file exists on your local system at this path: /Users/user/.nuget/packages/google.ortools/9.7.2996/lib/net6.0/Google.OrTools.dll

  4. If the DLL file doesn’t exist at that location, you can try deleting the “packages” folder at this path: /Users/user/.nuget/

  5. After deleting the “packages” folder, close your project and then reopen it. The “packages” folder should be recreated automatically, and you should find the DLL file in the specified path.

By following these steps, I was able to resolve my issue.

Confirmed, it works! 😃

  1. v9.7 meta package has been built on windows VM to have net462 support for windows (unity) user.

  2. On macos M1 (arm64) using the pet project https://www.or-tools.dev/dotnet_or-tools (using v9.7) dotnet run or dotnet run -r osx-arm64: will fail note: playing with ~/.nuget/package and ortools v9.7 v9.8LM I manage to get the error:

CSC : warning CS8012: Referenced assembly 'Google.OrTools, Version=9.7.2996.0, Culture=neutral, PublicKeyToken=53dbb1ea090cbef7' targets a different processor.
  1. Using dotnet run -r osx-x64 worked even if only an osx-arm64 dotnet-sdk is installed ! note: I thing under the hood rosetta2 compat manage to execute the osx-x64 byte code.

  2. I’ve created a v9.8LM (having only linux-x64 and osx-arm64 runtime and the meta has been built on linux-x64) with /p:Platform=x64 My guess is on unix \p:Platform is simply ignored on unix so when running on osx-arm64 it still manage to load them… note: using dotnet run -r osx-x64 with v9.8LM I got a error wihch is expected since this version only provide osx-arm64 rid.

$ dotnet run -r osx-x64
/usr/local/share/dotnet/sdk/7.0.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1156,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [/Users/.../dotnet_or-tools/project.csproj]
Unhandled exception. System.TypeInitializationException: The type initializer for 'Google.OrTools.LinearSolver.operations_research_linear_solverPINVOKE' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'google-ortools-native' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libgoogle-ortools-native, 0x0001): tried: 'libgoogle-ortools-native' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibgoogle-ortools-native' (no such file), '/usr/lib/libgoogle-ortools-native' (no such file, not in dyld cache), 'libgoogle-ortools-native' (no such file), '/usr/local/lib/libgoogle-ortools-native' (no such file), '/usr/lib/libgoogle-ortools-native' (no such file, not in dyld cache)
   at Google.OrTools.LinearSolver.operations_research_linear_solverPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_operations_research_linear_solver(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
   at Google.OrTools.LinearSolver.operations_research_linear_solverPINVOKE.SWIGExceptionHelper..cctor()
   --- End of inner exception stack trace ---
   at Google.OrTools.LinearSolver.operations_research_linear_solverPINVOKE.SWIGExceptionHelper..ctor()
   at Google.OrTools.LinearSolver.operations_research_linear_solverPINVOKE..cctor()
   --- End of inner exception stack trace ---
   at Google.OrTools.LinearSolver.operations_research_linear_solverPINVOKE.Solver_CreateSolver(String jarg1)
   at Google.OrTools.LinearSolver.Solver.CreateSolver(String solver_id)
   at BasicExample.Main() in /Users/.../dotnet_or-tools/BasicExample.cs:line 27
  1. On my way to create a v9.8WM (only windows-x64 and osx-arm64 rid + meta build on windows) and play with the /p:Platform flag… For the record:
  • /p:Platform=... was ignored
  • on windows the VS2022 dev prompt set the env variable Platform=x64

Need to postpone to v9.9 (or at least didn’t find why and how to fix it in a day) My dev note:

Meta nupkg

v9.4

%unzip -l google.ortools.9.4.1874.nupkg 
Archive:  google.ortools.9.4.1874.nupkg
  Length      Date    Time    Name
---------  ---------- -----   ----
      504  2022-08-11 14:35   _rels/.rels
     2248  2022-08-11 14:35   Google.OrTools.nuspec
  1601536  2022-08-11 12:35   lib/net6.0/Google.OrTools.dll
   727743  2022-08-11 12:35   lib/net6.0/Google.OrTools.xml
  1601536  2022-08-11 12:35   lib/netcoreapp3.1/Google.OrTools.dll
   727743  2022-08-11 12:35   lib/netcoreapp3.1/Google.OrTools.xml
    13822  2022-06-23 14:40   content/bop/bop_parameters.proto
     1763  2022-08-09 09:51   content/constraint_solver/assignment.proto
      988  2022-08-09 09:51   content/constraint_solver/demon_profiler.proto
     6656  2022-06-23 14:40   content/constraint_solver/routing_enums.proto
    27591  2022-06-23 14:40   content/constraint_solver/routing_parameters.proto
     1444  2022-06-23 14:40   content/constraint_solver/search_limit.proto
     3275  2022-06-23 14:40   content/constraint_solver/search_stats.proto
     3851  2022-06-23 14:40   content/constraint_solver/solver_parameters.proto
    24218  2022-06-23 14:40   content/glop/parameters.proto
     3161  2022-06-23 14:40   content/graph/flow_problem.proto
    30232  2022-06-23 14:40   content/linear_solver/linear_solver.proto
    18209  2022-06-23 14:40   content/pdlp/solvers.proto
    17346  2022-06-23 14:40   content/pdlp/solve_log.proto
     4725  2022-06-23 14:40   content/sat/boolean_problem.proto
    34080  2022-06-23 14:40   content/sat/cp_model.proto
     1363  2022-06-23 14:40   content/sat/cp_model_service.proto
    63760  2022-08-09 09:51   content/sat/sat_parameters.proto
     1347  2022-06-23 14:40   content/util/optional_boolean.proto
     6141  2020-04-27 07:55   content/orLogo.png
      647  2022-08-11 14:35   [Content_Types].xml
      731  2022-08-11 14:35   package/services/metadata/core-properties/2bf5c396282845a48b853e4c4ae536e0.psmdcp
     9476  2022-08-16 09:23   .signature.p7s
---------                     -------
  4936136                     28 files

vs v9.7

unzip -l Google.OrTools.9.7.2996.nupkg 
Archive:  Google.OrTools.9.7.2996.nupkg
  Length      Date    Time    Name
---------  ---------- -----   ----
      508  2023-08-09 09:07   _rels/.rels
     2336  2023-08-09 09:07   Google.OrTools.nuspec
  1716736  2023-08-09 16:07   lib/net462/Google.OrTools.dll
   806496  2023-08-09 16:07   lib/net462/Google.OrTools.xml
  1716736  2023-08-09 16:07   lib/net6.0/Google.OrTools.dll
   806496  2023-08-09 16:07   lib/net6.0/Google.OrTools.xml
    14109  2023-05-31 15:37   content/bop/bop_parameters.proto
     1832  2023-05-31 15:37   content/constraint_solver/assignment.proto
     1017  2023-02-20 12:20   content/constraint_solver/demon_profiler.proto
     6798  2023-02-20 12:20   content/constraint_solver/routing_enums.proto
    30381  2023-07-28 09:34   content/constraint_solver/routing_parameters.proto
     1483  2023-02-20 12:20   content/constraint_solver/search_limit.proto
     3519  2023-03-01 07:50   content/constraint_solver/search_stats.proto
     3991  2023-02-20 12:20   content/constraint_solver/solver_parameters.proto
    24913  2023-03-01 07:50   content/glop/parameters.proto
     3241  2023-03-01 07:50   content/graph/flow_problem.proto
    31046  2023-05-31 15:37   content/linear_solver/linear_solver.proto
    25874  2023-07-28 09:34   content/pdlp/solvers.proto
    21088  2023-05-31 15:37   content/pdlp/solve_log.proto
     4838  2023-02-20 12:20   content/sat/boolean_problem.proto
    35329  2023-05-31 15:37   content/sat/cp_model.proto
     1401  2023-02-20 12:20   content/sat/cp_model_service.proto
    73588  2023-07-28 09:34   content/sat/sat_parameters.proto
     1381  2023-02-20 12:20   content/util/optional_boolean.proto
     6141  2023-02-20 12:20   content/orLogo.png
      656  2023-08-09 09:07   [Content_Types].xml
      761  2023-08-09 09:07   package/services/metadata/core-properties/d353d211770446bbbf0dd6c3872c018c.psmdcp
---------                     -------
  5342695                     27 files

same layout, 9.4 TFM (net6.0 & netcoreapp3.1) vs v9.7 (net462 & net6.0) note: same observation when comparing .nuspec

Runtime nupkg

 %unzip -l v9.4/dotnet/google.ortools.runtime.osx-arm64.9.4.1874.nupkg 
Archive:  v9.4/dotnet/google.ortools.runtime.osx-arm64.9.4.1874.nupkg
  Length      Date    Time    Name
---------  ---------- -----   ----
      522  2022-08-11 08:53   _rels/.rels
      978  2022-08-11 08:53   Google.OrTools.runtime.osx-arm64.nuspec
  1625848  2022-08-11 06:53   runtimes/osx-arm64/native/google-ortools-native.dylib
 28061391  2022-08-11 06:53   runtimes/osx-arm64/native/libortools.9.dylib
     6141  2022-07-19 14:16   content/orLogo.png
      523  2022-08-11 08:53   [Content_Types].xml
      759  2022-08-11 08:53   package/services/metadata/core-properties/0ab742c31a1645e4a42139e06f671372.psmdcp
     9468  2022-08-16 07:56   .signature.p7s
---------                     -------
 29705630                     8 files

%unzip -l v9.7/dotnet/Google.OrTools.runtime.osx-arm64.9.7.2996.nupkg 
Archive:  v9.7/dotnet/Google.OrTools.runtime.osx-arm64.9.7.2996.nupkg
  Length      Date    Time    Name
---------  ---------- -----   ----
      522  2023-08-04 16:07   _rels/.rels
      978  2023-08-04 16:07   Google.OrTools.runtime.osx-arm64.nuspec
  2048888  2023-08-04 14:07   runtimes/osx-arm64/native/google-ortools-native.dylib
 29629279  2023-08-04 14:07   runtimes/osx-arm64/native/libortools.9.dylib
     6141  2022-07-19 14:16   content/orLogo.png
      523  2023-08-04 16:07   [Content_Types].xml
      777  2023-08-04 16:07   package/services/metadata/core-properties/5927a583f7aa40acad9dd5adac978fc7.psmdcp
---------                     -------
 31687108                     7 files

Using 9.4.* seems like a quick temp fix 👍🏼