[ASP.NET CORE] DB2 System.DllNotFoundException ‘libdb2.dylib’

หลังจากลองเอา Image ASP.NET Core มา Run ปรากฏว่าพบ Error

System.DllNotFoundException: Unable to load shared library 'libdb2.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable:liblibdb2.dylib: cannot open shared object file : No such file or directory
  at IBM.Data.DB2.Core.UnsafeNat iveMethods .DB232.SQLF reeConnAttribsADONET (DB2SQLGetConnAttribsADONETParams& pParam)
  at IBM.Data.DB2.Core.ConnSettingsFromXm1Config.Dispose(Boolean disposing)
  at IBM.Data.DB2.Core.ConnSettingsFromm1Config.Dispose()
  at IBM.Data.DB2.Core.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szvalue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach, Boolean pushDow
  at IBM.Data.DB2.Core.DB2Connection.set_Connectionstring(String value) 

ตอนแรกคิดว่า Image มันมีปัญหาอะไร หรือป่าว

  • อ้าวทำไม Linux มันไป Reference Library ของ Mac (-osx)

ทางแก้ไข

  • แก้ไข csproj ให้เลือก Library ในส่วนของ Unix เป็นของ Linux (-lnx)
<ItemGroup Condition="'$(OS)' == 'Unix'">
    <PackageReference Include="IBM.Data.DB2.Core-lnx" Version="3.1.0.500" />
    <PackageReference Include="IBM.EntityFrameworkCore-lnx" Version="3.1.0.500" />
    <!--
    <PackageReference Include="IBM.Data.DB2.Core-osx" Version="3.1.0.500" />
    <PackageReference Include="IBM.EntityFrameworkCore-osx" Version="3.1.0.500" />
    -->
</ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
    <PackageReference Include="IBM.Data.DB2.Core" Version="3.1.0.500" />
    <PackageReference Include="IBM.EntityFrameworkCore" Version="3.1.0.500" />
</ItemGroup>
  • อ่อ ถ้าจะแยก case ของ OSX มันไม่มี Const ให้ซะงั้นครับ

Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.