TgSharp icon indicating copy to clipboard operation
TgSharp copied to clipboard

Getting DataCenterMigrationException after Downloading Photo or File

Open pahager opened this issue 3 years ago • 2 comments

Hello everyone, as Title said I am getting DataCenterMigrationException after downloading any File or Photo here is my code for downloading Photo:

` var photo = (((TLMessageMediaPhoto)((TLMessage)message).Media).Photo as TLPhoto); // get photo TLPhotoSize photoSize = photo.Sizes.ToList().OfType<TLPhotoSize>().Last();

                                                var mb = 1048576;
                                                var upperLimit = (int)Math.Pow(2, Math.Ceiling(Math.Log(photoSize.Size, 2))) * 4;
                                                var limit = Math.Min(mb, upperLimit);

                                                var currentOffset = 0;

                                                var fileLocation = new TLInputPhotoFileLocation()
                                                {
                                                    AccessHash = photo.AccessHash,
                                                    Id = photo.Id,
                                                    FileReference = photo.FileReference,
                                                    ThumbSize = photoSize.Type,
                                                };

                                                using (var fs = File.OpenWrite("TestFile.jpg"))
                                                {
                                                    while (currentOffset < photoSize.Size)
                                                    {
                                                        var file = this.TelegramClient.GetFile(fileLocation, limit, currentOffset).ConfigureAwait(false).GetAwaiter().GetResult();
                                                        fs.Write(file.Bytes, 0, file.Bytes.Length);
                                                        currentOffset += file.Bytes.Length;
                                                        Thread.Sleep(500);
                                                    }
                                                    fs.Close();
                                                }`

so when I am trying to get another message or call any other Method I am getting this Exception and in Output i can see those lines: "TgSharp.Core.Network.Exceptions.UserMigrationException" in mscorlib.dll "TgSharp.Core.Network.Exceptions.UserMigrationException" in TgSharp.Core.dll "TgSharp.Core.Network.Exceptions.UserMigrationException" in mscorlib.dll "TgSharp.Core.Network.Exceptions.UserMigrationException" in TgSharp.Core.dll ...

Anyone knows how to handle this problem?

pahager avatar Jan 08 '22 23:01 pahager

I found the solution by adding this pull request https://github.com/nblockchain/TgSharp/pull/53 by @SmaGMan .

But now I am facing another problem. After restarting a program I am getting again loop

"TgSharp.Core.Network.Exceptions.UserMigrationException" in mscorlib.dll "TgSharp.Core.Network.Exceptions.UserMigrationException" in TgSharp.Core.dll

and can not connect to TelegramClient;

pahager avatar Jan 09 '22 14:01 pahager

@pahager Seems like you terminated the application when the auth was migrated to another DataCenter. This migrated auth was stored in the Session and now it cannot be used to establish the connection. Try to delete session.dat and perform a new authentication.

SmaGMan avatar Feb 03 '22 08:02 SmaGMan