GLPK System.IO.FileNotFoundException

152 views
Skip to first unread message

Mayron Rodrigues

unread,
Dec 19, 2020, 7:19:05 AM12/19/20
to OPTANO Modeling
I get the exception:

Could not load file or assembly 'libglpk-cli, Version=1.10.0.0, Culture=neutral, PublicKeyToken=null'.

When execute this C# code, line " solver.Solve(this.Model);" :

using (var solver = new OPTANO.Modeling.GLPK.GLPKSolver())                 
                    {
                        solver.Configuration.MIPGap = 0;                      
                        var solution = solver.Solve(this.Model);
                        if (solution.Status == OPTANO.Modeling.Optimization.Solver.SolutionStatus.Optimal)
                        {                          

                        }
                    }

My setup is:
- VS 2019
- Windows 10 64 bit
- OPTANO.Modeling" Version="3.6.0.510"
- OPTANO.Modeling.GLPK" Version="4.65.0"
- .NET 5.0

I copied binaries to project and set CopyToOutputDirectory Always and do not work.

I tried setup below and do not work:

<ItemGroup>
   
<Reference Include="libglpk-cli.dll">
     
<HintPath>..\glpk-4.65\w64\libglpk-cli.dll</HintPath>
   
</Reference>
 
</ItemGroup>

 
<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
   
<Copy SourceFiles="..\glpk-4.65\w64\glpk_4_65.dll" DestinationFolder="$(OutDir)" ContinueOnError="true" />
   
<Copy SourceFiles="..\glpk-4.65\w64\libglpk_cli_native.dll" DestinationFolder="$(OutDir)" ContinueOnError="true" />
 
</Target>


Mayron

jannic...@orconomy.de

unread,
Jan 4, 2021, 5:31:25 AM1/4/21
to OPTANO Modeling
Hello!

Please excuse the delayed response. I just returned from my Christmas Holidays.

Can you verify that your build target is properly executed, i.e. that glpk_4_65.dll and libglpkk_cli_native.dll are properly copied to your bin/debug/netcoreapp5.0 folder?
Another way to achieve this is adding the following elements to your csproj-file:

<ItemGroup>
  <None Include="..\your\custom\path\to\glpk-4.65\w64\glpk_4_65.dll">
    <Link>glpk_4_65.dll</Link>
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
  <None Include=" ..\your\custom\path\to\glpk-4.65\w64\libglpk_cli_native.dll">
    <Link>libglpk_cli_native.dll</Link>
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>

I hope this helps. Please let me know if you still run into problems.

Best Regards & a Happy New Year
Jannick Lange

Marcelo Lopes (mlopes)

unread,
Nov 27, 2022, 12:01:32 AM11/27/22
to OPTANO Modeling
Dear all,
I am experiencing the same problems described ('Could not load file or assembly 'libglpk-cli, Version=1.10.0.0, Culture=neutral, PublicKeyToken=null')
I have checked the requested libraries in the target directory and everything seems to be there (libglpk_cli_native.dll, libglpk-cli.dll and the glpk_4_65.dll).
I am compiling the project with Visual Studio 2022 and the target platform is the Dotnet Core 6.0.
Could you please shed some light on this?
Thank you for your attention,
Marcelo.

OPTANO Team

unread,
Nov 27, 2022, 1:54:48 AM11/27/22
to OPTANO Modeling
Hi
That happens, when dotnet does not find the Glpk dlls.
Please double check, that they are in the execution folder such as debug/x64 (might be different in your setting)

You may try to run the application manually by going into the outputt folder and starting it there, not using the debugger. That should be the place to copy all the DLLs to.

When that works, please follow the description above. It helps to automatically copy the dlls with each build.

Please also double check the build target of the application project in your solution. When using native dlls, it usually should by x64.
Do you use the DLLs of the right os?

Best jp

Marcelo Lopes (mlopes)

unread,
Nov 27, 2022, 6:51:41 AM11/27/22
to OPTANO Modeling
Hello,
Thank you for your attention.
In fact, I had already done that (running manually from the x64/Debug/net6.0-windows directory). 
After that, I have also copied all GLPK files from the w64 directory to the  x64/Debug/net6.0-windows directory, but the effect is always the same: "Could not load the file or assembly 'libglpk-cli'".
I have also removed the glpk path from the system configuration and opened a command prompt ensuring the glpsol could be opened just from the x64/Debug/net6.0-windows directory.
The system keeps issuing the same error message.
Thank you again,
Marcelo.

OPTANO Team

unread,
Nov 27, 2022, 7:06:13 AM11/27/22
to OPTANO Modeling
Could you dump the directory file list here?

Marcelo Lopes (mlopes)

unread,
Nov 27, 2022, 7:51:07 AM11/27/22
to OPTANO Modeling
Hello.
I have rebuilt everything and cleaned the GLPK stuff.
The glpk/w64 is in the path and the glpsol could be accessed from any directory:

D:\>glpsol
GLPSOL: GLPK LP/MIP Solver, v4.65
No input problem file specified; try glpsol --help

The content of the GLPKTest\bin\x64\Debug\net6.0-windows directory is:

27/11/2022  09:08    <DIR>          .
27/11/2022  09:08    <DIR>          ..
27/11/2022  09:08    <DIR>          cs
27/11/2022  09:08    <DIR>          de
27/11/2022  09:08    <DIR>          en
27/11/2022  09:08    <DIR>          es
27/11/2022  09:08    <DIR>          fr
27/11/2022  09:08    <DIR>          it
27/11/2022  09:08    <DIR>          ja
27/11/2022  09:08    <DIR>          ko
27/11/2022  09:08    <DIR>          pl
27/11/2022  09:08    <DIR>          pt-BR
27/11/2022  09:08    <DIR>          ru
27/11/2022  08:54    <DIR>          runtimes
27/11/2022  09:08    <DIR>          tr
27/11/2022  09:08    <DIR>          zh-Hans
27/11/2022  09:08    <DIR>          zh-Hant
20/08/2017  19:44           237.568 FParsec.dll
20/08/2017  19:44           117.760 FParsecCS.dll
26/11/2018  15:51         2.701.360 FSharp.Core.dll
17/03/2018  16:06         1.880.064 glpk_4_65.dll
27/11/2022  09:08            61.404 GLPKTest.deps.json
27/11/2022  09:08             7.680 GLPKTest.dll
27/11/2022  09:08           147.968 GLPKTest.exe
27/11/2022  09:08            13.520 GLPKTest.pdb
27/11/2022  09:08               266 GLPKTest.runtimeconfig.json
17/03/2018  16:08           704.000 libglpk_cli_native.dll
17/03/2018  16:08           121.856 libglpk-cli.dll
11/11/2018  16:42         1.625.088 MathNet.Numerics.dll
11/11/2018  16:43           474.136 MathNet.Numerics.FSharp.dll
18/11/2018  07:02           448.536 MathNet.Symbolics.dll
14/03/2019  19:39           219.000 Microsoft.Z3.dll
09/11/2020  10:39         2.890.752 optano.modeling.dll
20/04/2021  05:09            29.184 OPTANO.Modeling.GLPK.dll
              17 arquivo(s)     11.680.142 bytes
              17 pasta(s)   30.508.388.352 bytes disponíveis

Thank you again,
Marcelo.

OPTANO Team

unread,
Nov 27, 2022, 8:51:08 AM11/27/22
to OPTANO Modeling
Hi

look's good. Could you double check the csproj files. does it have item entries comparable to this one? Could you past it as well?


It shall link to the *cli.dll. 

OPTANO Team

unread,
Nov 27, 2022, 9:27:06 AM11/27/22
to OPTANO Modeling
I have created a blank project
> dotnet create console
and added the glpk package reference
> dotnet add package optano.modeling.glpk

then, one needs to copy the 3 dlls to the source folder:
* libgplk-cli.dll (the dotnet managed dll)
* libgplk_cli_native.dll  (the native backend of the cli)
* glpk_4_65.dll the solver

the first one will be added as reference, the latter ones as outputs "copy always"


that should bring up this project, which actually works. 
Your project.cs looks slightly different. The dll-file type extension is missing in mine for the reference, the copy always section is also different. I have used dotnet 7, thou this is supposed to be working on all dotnet versions including 5. 

The projcs file

 

<Project Sdk="Microsoft.NET.Sdk">

 

  <PropertyGroup>

    <OutputType>Exe</OutputType>

    <TargetFramework>net7.0</TargetFramework>

    <ImplicitUsings>enable</ImplicitUsings>

    <Nullable>enable</Nullable>

  </PropertyGroup>

 

  <ItemGroup>

    <PackageReference Include="OPTANO.Modeling.GLPK" Version="4.65.2" />

  </ItemGroup>

 

  <ItemGroup>

    <Reference Include="libglpk-cli">

      <HintPath>libglpk-cli.dll</HintPath>

    </Reference>

  </ItemGroup>

 

  <ItemGroup>

    <None Update="glpk_4_65.dll">

      <CopyToOutputDirectory>Always</CopyToOutputDirectory>

    </None>

    <None Update="libglpk_cli_native.dll">

      <CopyToOutputDirectory>Always</CopyToOutputDirectory>

    </None>

  </ItemGroup>

 

</Project>

 

 

 

 

The program.cs file

 

 

// See https://aka.ms/new-console-template for more information

using Microsoft.Z3;

using OPTANO.Modeling.GLPK;

using OPTANO.Modeling.Optimization;

 

internal class Program

{

    private static void Main(string[] args)

    {

        Console.WriteLine("Hello, World!");

        var model = new OPTANO.Modeling.Optimization.Model();

        var varX = new Variable("x");

        model.AddObjective(new OPTANO.Modeling.Optimization.Objective(varX*2,"obj1"));

 

        var solver = new GLPKSolver();

        solver.Solve(model);

        Console.WriteLine(solver.ToString());

    }

}

mayro...@gmail.com schrieb am Samstag, 19. Dezember 2020 um 13:19:05 UTC+1:

Marcelo Lopes (mlopes)

unread,
Nov 27, 2022, 9:51:35 AM11/27/22
to OPTANO Modeling
Hello,
Thank you so much for all your effort and support.

The section below, in the project file solved the problem:
  <ItemGroup>
    <Reference Include="libglpk-cli">
      <HintPath>libglpk-cli.dll</HintPath>
    </Reference>
  </ItemGroup>  

Thank you again and Best Regards,
Marcelo.

OPTANO Team

unread,
Nov 27, 2022, 10:00:30 AM11/27/22
to OPTANO Modeling
Great. You're welxome.


That is the "add reference" feature of a visual studio project and then using browse in the popup
Reply all
Reply to author
Forward
0 new messages