egramtel / tdsharp

C#/.NET Core bindings for TDLib (Telegram MTProto API)
MIT License
246 stars 61 forks source link

[Azure] Unable to load DLL 'tdjson.dll' or one of its dependencies #39

Closed aloji closed 4 years ago

aloji commented 4 years ago

Hi @ForNeVeR, @x2bool,

The app logged this error when deploying in azure web app service. Any ideas?

System.DllNotFoundException: Unable to load DLL 'tdjson.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) at TdLib.Bindings.WindowsBindings.td_json_client_create() at TdLib.TdJsonClient..ctor() at TdLib.TdClient..ctor()

    <TargetFramework>netcoreapp2.2</TargetFramework>

    <PackageReference Include="TDLib" Version="1.6.0" />
    <PackageReference Include="tdlib.native" Version="1.6.0" />

I can see the dll in the machine

image

The service is configured on 64 bit

Regards,

ForNeVeR commented 4 years ago

I'm not aware how Azure works, sorry :( Could you check if the file is in actual file system on the server after deployment?

aloji commented 4 years ago

Yes, the file exists in the folder win-x64

And the TDLib.dll, TDLib.Api.dll files also exist

But I do not see the td.binlog

I will continue investigating :(

ForNeVeR commented 4 years ago

Oh, it could be not tdlibjson.dll directly, but some of dependencies. In such cases, it could be hard to determine which one it couldn't found. Does Azure have RDP access? The easiest way to debug DLL dependency load failure is to fire up procmon.exe.

aloji commented 4 years ago

Hi @ForNeVeR

I can not found in azure web app what is the problem. :/

Now, I'm try to deploying in a docker linux and logged this error.

fail: System.DllNotFoundException: Unable to load shared library 'tdjson' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libtdjson: cannot open shared object file: No such file or directory at TdLib.Bindings.LinuxBindings.td_json_client_create() at TdLib.TdJsonClient..ctor() at TdLib.TdClient..ctor()

Could you help me?

Regards

aloji commented 4 years ago

Hi

Is possible that only run in windows 10? because I run in win server 2016 and received the same error and run in other window 10 and working fine.

Regards

ForNeVeR commented 4 years ago

@aloji

  1. Which Linux distribution do you use? tdlib.native is tested on Ubuntu x64. In case you have another distribution, then it depends whether it should work out-of-the-box or not.

    Also, you could really try to set up LD_DEBUG and debug the process of library search (I am not a Linux expert though, so I'm sorry but I've no additional info on how this work).

  2. It is strange that it doesn't work on Windows Server 2016, but it is good that it fails on a non-cloud OS distrituition I could set up and check what it lacks of.

    But, since already have a Win Server 2016 handy, could you please debug it with Process Monitor? You should start Process Monitor and set the filter for dotnet.exe process (or whatever your process is called), and then reproduce your issue. Then you could attach the activity snapshot here if you don't want to read it yourself.

aloji commented 4 years ago

@ForNeVeR

Please, check the code in https://github.com/aloji/TelegramTdLib

For Windows OS

When I copy the files generated in debug folder and run in other machine (dotnet TelegramTdLib.dll), the app throw the exception:

System.DllNotFoundException: Unable to load DLL 'tdjson.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at TdLib.Bindings.WindowsBindings.td_set_log_verbosity_level(Int32 level)

I added <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to enforce copying NuGet assemblies to the built output.

This are the log file filtered by process name dotnet.exe

TelegramTdLib.zip

The debug folder: debug.zip

Thank you for your help.

ForNeVeR commented 4 years ago

@aloji, thanks for additional information, I think I've found the issue: tdlib built with default settings requires Visual Studio 2015 redistributable (namely, MSVCP140.dll) being installed on the target system.

For now, you could deal with it either by installing a redistributable package or packing this file together with your application.

In the meantime, I'll see what could be done to statically build this library with the binary, or require some runtime library version that is already installed by .NET Core distribution.

ForNeVeR commented 4 years ago

I have reported the issue to tdlib.native: https://github.com/ForNeVeR/tdlib.native/issues/29.

aloji commented 4 years ago

@ForNeVeR

I installed the redistributable package and now I can see the dll in system32 but the problem persist :/

The new logs after installed MSVCP140.dll

TelegramTdLib2.zip

ForNeVeR commented 4 years ago

I'm sorry, I've been wrong earlier. Now it looks for vcruntime140_1.dll which is part of the combined VS2015, 2017 and 2019 runtime. Please try that one.

aloji commented 4 years ago

Now is working... Thanks a lot.

Jycjmf commented 3 years ago

Now is working... Thanks a lot.

Hi bro, I have met the same problem on ubuntu, It works fine on windows server after I install "combined VS2015, 2017 and 2019 runtime" . But how can I install it on ubuntu? It sames useless to just copy "vcruntime140_1.dll" in the floder , Thank you. image

ForNeVeR commented 3 years ago

Ubuntu version doesn't depend on VC Runtime (since it's technically impossible). It depends on something else. For start, could you please share your .csproj file?

Jycjmf commented 3 years ago

Ubuntu version doesn't depend on VC Runtime (since it's technically impossible). It depends on something else. For start, could you please share your .csproj file?

Ok,here are my.csproj file content:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Platforms>AnyCPU;x64</Platforms>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Magick.NET-Q16-x64" Version="8.2.1" />
    <PackageReference Include="Magick.NET.Core" Version="8.2.1" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="System.Text.Json" Version="5.0.2" />
    <PackageReference Include="TDLib" Version="1.7.0" />
    <PackageReference Include="TDLib.Api" Version="1.7.0" />
    <PackageReference Include="Telegram.Bot" Version="16.0.2" />
  </ItemGroup>

</Project>
ForNeVeR commented 3 years ago

Please try adding a tdlib.native package.

Jycjmf commented 3 years ago

Please try adding a tdlib.native package.

Thanks bro, I forgot I have only compiled tdjson.dll for windows , It works fine after install tdlib.native.

taeyeonlee commented 2 years ago

Hi @ForNeVeR, @x2bool,
The app logged this error when deploying in Unity Android app. Any ideas?
The app is working fine in Unity Editor (Windows), but it doesn't work in Unity Android phone app.

2022-02-06 22:30:16.570 27342-27363/? E/Unity: DllNotFoundException: Unable to load DLL 'tdjson': The specified module could not be found.
at TdLib.Bindings.LinuxBindings.td_json_client_create () [0x00000] in <00000000000000000000000000000000>:0
at TdLib.TdJsonClient..ctor (TDLib.Bindings.ITdLibBindings bindings) [0x00000] in <00000000000000000000000000000000>:0
at TdLib.TdClient..ctor (TDLib.Bindings.ITdLibBindings bindings) [0x00000] in <00000000000000000000000000000000>:0
at Telegram.Chat.ChatPanel+d__21.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0
at Telegram.Chat.ChatPanel.telegramInit () [0x00000] in <00000000000000000000000000000000>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
at System.Th

Ref : Unity : https://unity.com/

YauheniKhadanovich commented 2 years ago

@taeyeonlee Can you suggest a solution? Installed https://github.com/GlitchEnzo/NuGetForUnity on Unity. Imported Tdlib.dll, Tdlib.Api.dll, tdjson.dll. It works fine on Windows. But from Android apk i have error: DllNotFoundException: tdjson.dll

taeyeonlee commented 2 years ago

I didn't find a way to use the Tdlib libraries for Android.

On Mon, Apr 4, 2022 at 1:09 AM Jeffy94 @.***> wrote:

@taeyeonlee https://github.com/taeyeonlee Can you suggest a solution? Installed https://github.com/GlitchEnzo/NuGetForUnity on Unity. Imported Tdlib.dll, Tdlib.Api.dll, tdjson.dll. It works fine on Windows. But from Android apk i have error: DllNotFoundException: tdjson.dll

— Reply to this email directly, view it on GitHub https://github.com/egramtel/tdsharp/issues/39#issuecomment-1086898944, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUTYI5CM5S6VRNLZ62JI63DVDG7CJANCNFSM4K7XTFTQ . You are receiving this because you were mentioned.Message ID: @.***>

YauheniKhadanovich commented 2 years ago

maybe there are other ways to integrate the Telegram API into Unity?

VadimAND commented 6 months ago

There was a problem when changing the version from .NET 7 to .NET 8

The error only appears when using Docker. The build file remains the same.

The error appears when creating a client: _client = new TdClient();

Package versions TDLib (1.8.21) TDLib.Api (1.8.21) tdlib.native(1.8.21)

libraries in the runtimes/linux-x64/native folder: libtdactor.a libtdapi.a libtdclient.a libtdcore.a libtddb.a libtdjson.so libtdjson.so.1.8.21 libtdjson_private.a libtdjson_static.a libtdnet.a libtdsqlite.a libtdutils.a

Question: Will the problem be solved somehow?

The error itself: Unable to load shared library 'tdjson' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: /app/bin/Debug/net8.0/runtimes/linux-x64/native/tdjson.so: cannot open shared object file: No such file or directory /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.4/tdjson.so: cannot open shared object file: No such file or directory /app/bin/Debug/net8.0/tdjson.so: cannot open shared object file: No such file or directory libssl.so.1.1: cannot open shared object file: No such file or directory /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.4/libtdjson.so: cannot open shared object file: No such file or directory /app/bin/Debug/net8.0/libtdjson.so: cannot open shared object file: No such file or directory /app/bin/Debug/net8.0/runtimes/linux-x64/native/tdjson: cannot open shared object file: No such file or directory /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.4/tdjson: cannot open shared object file: No such file or directory /app/bin/Debug/net8.0/tdjson: cannot open shared object file: No such file or directory /app/bin/Debug/net8.0/runtimes/linux-x64/native/libtdjson: cannot open shared object file: No such file or directory /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.4/libtdjson: cannot open shared object file: No such file or directory /app/bin/Debug/net8.0/libtdjson: cannot open shared object file: No such file or directory

ForNeVeR commented 6 months ago

Please open new reports on tdlib.native repo if you have problems with its packages.

You are free to provide your own implementation as well; tdsharp is not tied to tdlib.native.