diff --git a/Examples/Program_ReactorError.cs b/Examples/Program_ReactorError.cs index 370da34..83c2d6f 100644 --- a/Examples/Program_ReactorError.cs +++ b/Examples/Program_ReactorError.cs @@ -50,7 +50,7 @@ namespace WTelegramClientTest await CreateAndConnect(); break; } - catch (Exception ex) + catch (Exception ex) when (ex is not ObjectDisposedException) { Console.WriteLine("Connection still failing: " + ex.Message); } diff --git a/src/Client.cs b/src/Client.cs index 89589af..bf4ee87 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -465,21 +465,29 @@ namespace WTelegram Helpers.Log(1, $"{_dcSession.DcID}>Ignoring 0x{ctorNb:X8} because of wrong timestamp {msgStamp:u} - {utcNow:u} Δ={new TimeSpan(_dcSession.ServerTicksOffset):c}"); return null; } - if (ctorNb == Layer.MsgContainerCtor) + try { - Helpers.Log(1, $"{_dcSession.DcID}>Receiving {"MsgContainer",-40} {msgStamp:u} (svc)"); - return ReadMsgContainer(reader); + if (ctorNb == Layer.MsgContainerCtor) + { + Helpers.Log(1, $"{_dcSession.DcID}>Receiving {"MsgContainer",-40} {msgStamp:u} (svc)"); + return ReadMsgContainer(reader); + } + else if (ctorNb == Layer.RpcResultCtor) + { + Helpers.Log(1, $"{_dcSession.DcID}>Receiving {"RpcResult",-40} {msgStamp:u}"); + return ReadRpcResult(reader); + } + else + { + var obj = reader.ReadTLObject(ctorNb); + Helpers.Log(1, $"{_dcSession.DcID}>Receiving {obj.GetType().Name,-40} {msgStamp:u} {((seqno & 1) != 0 ? "" : "(svc)")} {((msgId & 2) == 0 ? "" : "NAR")}"); + return obj; + } } - else if (ctorNb == Layer.RpcResultCtor) + catch (Exception ex) { - Helpers.Log(1, $"{_dcSession.DcID}>Receiving {"RpcResult",-40} {msgStamp:u}"); - return ReadRpcResult(reader); - } - else - { - var obj = reader.ReadTLObject(ctorNb); - Helpers.Log(1, $"{_dcSession.DcID}>Receiving {obj.GetType().Name,-40} {msgStamp:u} {((seqno & 1) != 0 ? "" : "(svc)")} {((msgId & 2) == 0 ? "" : "NAR")}"); - return obj; + Helpers.Log(4, $"While deserializing frame #{ctorNb:x}: " + ex.ToString()); + return null; } } @@ -916,6 +924,7 @@ namespace WTelegram TLConfig = new Config { this_dc = _session.MainDC, dc_options = _session.DcOptions }; else { + if (_dcSession.Layer != 0 && _dcSession.Layer != Layer.Version) _dcSession.Renew(); var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonDocument.Parse(Config("init_params")).RootElement); TLConfig = await this.InvokeWithLayer(Layer.Version, new TL.Methods.InitConnection