0

I use Z3 via NuGet package in my .NET Core 2.1 project and recently tried to update from version 4.5.0.1 to 4.8.1. Then I reverted back to 4.5.0.1 and got this exception at context creation:

using(var ctx = new Microsoft.Z3.Context())
{

}

System.DllNotFoundException: Unable to load DLL 'libz3.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I checked the following:

  • my app is compiled for x64 and I use z3x64win package,
  • both libz3.dll and Microsoft.Z3.dll are stored in %userprofile%\.nuget\packages\z3x64win\4.5.0.1\lib,
  • tried to add this path to the PATH environment variable as described here but it did not help,
  • tried to manually save libz3.dll and Microsoft.Z3.dll to bin directory of the project but the problem persists.

Are there any other necessary steps to refer Z3?

FIL
  • 1,148
  • 3
  • 15
  • 27
  • I don't know if that's the case, but I had a similar issue when the arch of the DLL didn't match the one of my program (e.g., if your exe is compiled for x86 but the DLL you are trying to load is x64). OR you are missing additional dependencies required by libz3.dll – Sergio Monteleone Dec 09 '18 at 12:54
  • My app is compiled for x64 and I use z3x64win package. libz3.dll does not require any dependencies. – FIL Dec 09 '18 at 13:03
  • "or one of its dependencies" is the issue, the package author did not include them. You need to download and run [this](https://www.microsoft.com/en-us/download/details.aspx?id=40784). – Hans Passant Jun 05 '19 at 22:25

2 Answers2

0

Back in the days I remember having these problems with Z3 and often it worked by trying the following:

  • Remove and reset your Microsoft.Z3.dll reference completely. Make sure the csproj file is clean from references before adding the reference again.
  • Re-download or get Z3 dll's so that you are hundred procent sure they match and that VS or your environment don't use cache.

  • Are you sure both libz3.dll and z3.exe is in your PATH?

0

There is now an official .NET Core Z3 NuGet package which should solve all your issues: https://www.nuget.org/packages/Microsoft.Z3.x64/

ahelwer
  • 1,441
  • 13
  • 29
  • No, still the same problem. Using dumpbin.exe /imports on libz3.dll reveals it has a dependency on msvcr120.dll, vcomp120.dll and msvcp120.dll. The package does not include them. Download and run the vcredist for VS2013. – Hans Passant Jun 04 '19 at 21:33
  • If you're running .NET Core, all you should have to do is run "dotnet add package Microsoft.Z3.x64" in the same directory as your project, then it should take care of everything else. What issue are you seeing? – ahelwer Jun 05 '19 at 22:19