wiz0u / WTelegramClient

Telegram Client API (MTProto) library written 100% in C# and .NET
https://wiz0u.github.io/WTelegramClient/
MIT License
996 stars 164 forks source link

Operation is not supported on this platform. (Android) #181

Closed ghost closed 1 year ago

ghost commented 1 year ago

I am developing a .NET MAUI app and I use WTelegramClient to work with Telegram API

When I am trying to login the user Only on Android, I get the error

[0:] System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.ConsolePal.set_ForegroundColor(ConsoleColor value)
   at System.Console.set_ForegroundColor(ConsoleColor value)
   at WTelegram.Helpers.DefaultLogger(Int32 level, String message)
   at WTelegram.Client..ctor(Func`2 configProvider, Stream sessionStore)
   at WTelegram.Client..ctor(Int32 apiID, String apiHash, String sessionPathname)
   at BackEnd.Client.Login(String phoneNumber)

My custom path on android is "/data/data/com.{name}.{name}/files/{name}.session This does not happen on Windows How can I resolve this?

Lenkoras commented 1 year ago

From the exception message and stack trace, I believe that you need to redefine Helpers.Log. By default used console logger, that writes all messages to the Console.Out. But android os does not support such logging. So, you should set a custom Action<int, string> to this property (Helpers.Log). This action should provide logging logic for WTelegramClient. It'll log there all info about work and possible future exceptions, so it is really necessary.

ghost commented 1 year ago

Will this get fixed in future updates so the library will be cross-platform?

wiz0u commented 1 year ago

You need to redirect logging to a file, to System.Diagnostics.Debug.WriteLine or a logger of your choice, because the default logging to Console is not supported on Android.

I don't plan to make special case for Android, as the solution is pretty straightforward and no serious software should leave the defaut console logging anyway, especially on a device with no console. You need to be able to diagnose upcoming issues with your app.

See also issue #62

ghost commented 1 year ago

Thank you for your help, it works fine now