Z
Z
Zloe_apple2018-10-17 14:17:03
C++ / C#
Zloe_apple, 2018-10-17 14:17:03

In vkNet.dll v 1.38.0, when using the "Messages.GetHistory" method in a loop, a NullReferenceException is thrown. Why and how to get around it?

Hello!
I use the vkNet library to create a chat analyzer on Vkontakte. On the 53rd cycle (when i = 10600) I catch a NullReferenceException, if I wrap the code in try and work out this exception, then the next time it will jump out by 17k then by 40k, etc.
This exception did not appear immediately, at first everything worked. How to get around this exception?

for (int i = 0; ; i += 200)
            {
             var GetMessages = Vkontakte.Messages.GetHistory(new MessagesGetHistoryParams //вот тут вылетает исключение
                    {
                        @PeerId = ChatID,
                        @Count = 199,
                        @Offset = i,
                        @Reversed = true
                    });
                    if (GetMessages .Messages.Count == 0)
                    {
                        MessageBox.Show("Загрузка Завершена");
                        break;
                    }
                    
            }

PS If you set the loop condition like this:
for (int i = 10600;i<=10800 ; i += 200)//NullReferenceException
            {
             ...
            }

the exception flies at once.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question