Problem with Google's OR-Tools

368 views
Skip to first unread message

Lucas Dias

unread,
Jun 25, 2022, 9:34:09 PM6/25/22
to Excel-DNA
Hi Govert and all,

I'm having trouble when integrating ExcelDNA with Google's OR-Tools (math optimization lib). It works in a standalone console app, but gives the following error inside a compiled UDF:
Exception thrown: 'System.TypeInitializationException' in Google.OrTools.dll


I uploaded a test repo at: https://github.com/lukedays/DnaTest

Versions: .NET 6, ExcelDNA 1.6.0-preview3.

Any clues?
Thanks in advance!

Lucas Dias

unread,
Jun 25, 2022, 9:59:50 PM6/25/22
to Excel-DNA
Just tried another library (Microsoft Solver Foundation). Similar error:

Exception thrown: 'System.TypeLoadException' in Test

When using .NET Framework, it works. So I imagine it's related to .NET Core.

Lucas Dias

unread,
Jun 28, 2022, 10:28:30 AM6/28/22
to Excel-DNA
I saw a recent merge on GitHub related to types. Maybe it is related to this issue.
Could you please push a new 1.6.0 preview?
I'd happy to do further tests and help with the project. We have a lot of VBA code that I want to migrate to .NET.
Unfortunately MS is giving little support for API's other than JavaScript.
Thanks again for the library!

Govert van Drimmelen

unread,
Jun 28, 2022, 11:22:20 AM6/28/22
to exce...@googlegroups.com

--------------------------------------------------

Excel-DNA is now registered on GitHub Sponsors.

With a small monthly contribution you encourage further development and support.

--------------------------------------------------

Hi Lucas,

 

I had a look at your Google OR-Tools test, and had to make two changes to get it to work:

  • I changed the TargetFramework in the .csproj file to “net6.0-windows”. Otherwise the correct Excel-DNA reference is not taken, as you’ll see in an awkward build warning.
  • I copied the OR-Tools runtime file from bin\Debug\net6.0-windows\runtimes\win-x64\native\google-ortools-native.dll in the bin\Debug\net6.0-windows directory itself. I don’t know how the OR-Tools library is set up to find and load the native .dll, but I guess that part does not work as expected when running in the Excel process. Often the probing for the native files is done relative to the process directory, which in this case won’t work. But they might have another plan. You should probably set up a post-build event to copy the file into the output.

 

After that it seems to run OK.

 

I don’t think Microsoft Solver Foundation is an active project anymore, and StackOverflow says it does not work with .NET Core (.NET 6): c# - Solver Foundation with net5 - Stack Overflow

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/70a49b82-7599-4adf-97a8-675a8f0c108bn%40googlegroups.com.

Lucas Dias

unread,
Jun 28, 2022, 12:03:48 PM6/28/22
to Excel-DNA
Excellent!! Worked perfectly. Thank you very much.

I updated the repo in case anyone stumbles with this problem. https://github.com/lukedays/ExcelDnaGoogleORTools

Reply all
Reply to author
Forward
0 new messages