Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting DataCenterMigrationException after Downloading Photo or File #56

Open
pahager opened this issue Jan 8, 2022 · 2 comments
Open

Comments

@pahager
Copy link

pahager commented Jan 8, 2022

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().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
Copy link
Author

pahager commented Jan 9, 2022

I found the solution by adding this pull request #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;

@SmaGMan
Copy link

SmaGMan commented Feb 3, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants