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
v9.8 should be published and may fix this recurring issue…
mostly the fix was: https://github.com/google/or-tools/blob/43e400c4f2749268d6a53d39be8f019906fd19c9/tools/release/build_delivery_win.cmd#L131
and:
https://github.com/google/or-tools/blob/43e400c4f2749268d6a53d39be8f019906fd19c9/cmake/dotnet.cmake#L346-L347 https://github.com/google/or-tools/blob/43e400c4f2749268d6a53d39be8f019906fd19c9/cmake/dotnet.cmake#L369-L373
ref: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build#arguments
May have found the bug https://github.com/google/or-tools/blob/a33bf9a8d80711f4bb80199aa88d64506cfb8812/cmake/dotnet.cmake#L49-L53
When building a Multi-platform package (i.e.
-DUNIVERSAL_DOTNET_PACKAGE=ON
) we should not set the platform (or set it toAnyCPU
) https://github.com/google/or-tools/blob/a33bf9a8d80711f4bb80199aa88d64506cfb8812/cmake/dotnet.cmake#L346-L356 https://github.com/google/or-tools/blob/a33bf9a8d80711f4bb80199aa88d64506cfb8812/cmake/dotnet.cmake#L365-L368On my way to test it…
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:
Change your build settings from x64/x86 to Any CPU.
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.
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
If the DLL file doesn’t exist at that location, you can try deleting the “packages” folder at this path:
/Users/user/.nuget/
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! 😃
v9.7 meta package has been built on windows VM to have net462 support for windows (unity) user.
On macos M1 (arm64) using the pet project https://www.or-tools.dev/dotnet_or-tools (using v9.7)
dotnet run
ordotnet run -r osx-arm64
: will fail note: playing with~/.nuget/package
and ortools v9.7 v9.8LM I manage to get the error:Using
dotnet run -r osx-x64
worked even if only anosx-arm64
dotnet-sdk is installed ! note: I thing under the hood rosetta2 compat manage to execute theosx-x64
byte code.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 onosx-arm64
it still manage to load them… note: usingdotnet run -r osx-x64
with v9.8LM I got a error wihch is expected since this version only provideosx-arm64
rid./p:Platform
flag… For the record:/p:Platform=...
was ignoredPlatform=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
vs v9.7
same layout, 9.4 TFM (net6.0 & netcoreapp3.1) vs v9.7 (net462 & net6.0) note: same observation when comparing
.nuspec
…Runtime nupkg
Using
9.4.*
seems like a quick temp fix 👍🏼