.NET 4.x Не получается передать параметры в метод - C#

Узнай цену своей работы

Формулировка задачи:

Доброго времени суток. Использую библиотеку VkNet. Пытаюсь получить пост используя wall.getById()
Листинг программы
  1. long groupId = -11111111;
  2. long postIds = 333;
  3.  
  4. ICollection<KeyValuePair<long, long>> posts = new Dictionary<long, long>();
  5. posts.Add(new KeyValuePair<long, long>(groupId, postIds));
  6. var copyPost = vk.Wall.GetById(posts); <-- В этом месте вываливается ошибка.
Листинг программы
  1. An unhandled exception of type 'System.NullReferenceException' occurred in VkNet.dll
  2. Additional information: Ссылка на объект не указывает на экземпляр объекта.
Не могу понять где я ошибаюсь

Решение задачи: «.NET 4.x Не получается передать параметры в метод»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using VkNet;
  12. using VkNet.Enums;
  13. using VkNet.Enums.Filters;
  14. using VkNet.Model;
  15. using VkNet.Model.Attachments;
  16.  
  17. namespace wallCopyPostVk
  18. {
  19.     public partial class Form1 : Form
  20.     {
  21.         public static VkApi vk = new VkApi();
  22.  
  23.         long groupId = -****;//Одкуда берем посты
  24.         long myGroups = -***;//Куда копируем посты
  25.  
  26.         public Form1()
  27.         {
  28.             InitializeComponent();
  29.            
  30.         }
  31.        
  32.  
  33.         private void Form1_Load(object sender, EventArgs e)
  34.         {
  35.             int appId = 4857486; // указываем id приложения
  36.             string email = "*******"; // email для авторизации
  37.             string password = "q*****"; // пароль
  38.             Settings settings = Settings.All; // уровень доступа к данным
  39.             vk.Authorize(appId, email, password, settings);
  40.  
  41.  
  42.    
  43.         }
  44.  
  45.         private void button1_Click(object sender, EventArgs e)
  46.         {
  47.  
  48.             int totalCount;
  49.             ReadOnlyCollection<Post> listPost = vk.Wall.Get(groupId, out totalCount, 50, 0, WallFilter.All);
  50.  
  51.  
  52.             listView1.View = View.Details;
  53.             listView1.GridLines = true;
  54.             listView1.FullRowSelect = true;
  55.             listView1.CheckBoxes = true;
  56.             listView1.Columns.Add("Text");
  57.             listView1.Columns.Add("postId");
  58.             listView1.Columns.Add("attachment");
  59.             listView1.Items.Clear();
  60.             for (int i = 0; i < listPost.Count(); i++ )
  61.             {
  62.                 listView1.Items.Add(listPost[i].Text);
  63.                 listView1.Items[i].SubItems.Add(listPost[i].Id.ToString());
  64.                 //listView1.Items[i].SubItems.Add(listPost[i].Attachment.ToString());
  65.             }
  66.  
  67.         }
  68.  
  69.         private void button2_Click(object sender, EventArgs e)
  70.         {
  71.             DateTime timesAdd = DateTime.Now;
  72.             timesAdd = timesAdd.AddMinutes(30);
  73.  
  74.             int totalCount;
  75.  
  76.             ReadOnlyCollection<Post> listPost = vk.Wall.Get(groupId, out totalCount, 50, 0, WallFilter.All);
  77.  
  78.             var attachments = new List<MediaAttachment>
  79.             {
  80.                
  81.             };
  82.  
  83.             foreach (var test in listPost)
  84.             {
  85.                 MessageBox.Show(test.Attachments.ToList().ToString());
  86.             }
  87.  
  88.  
  89.             for (int i = 0; i < listView1.Items.Count; i++)
  90.             {
  91.                 if (listView1.Items[i].Checked == true)
  92.                 {
  93.                     string[] post = { groupId + "_" + listView1.Items[i].SubItems[1].Text };
  94.                     //long postIds = Convert.ToInt64(listView1.Items[i].SubItems[1].Text);
  95.                     //IEnumerable<string> posts = new ;
  96.                     //vk.Wall.GetById(posts);
  97.  
  98.  
  99.  
  100.                     var result = vk.Wall.Post(myGroups, false, true, listView1.Items[i].SubItems[0].Text,null, null, null, false, timesAdd);
  101.  
  102.                                                    
  103.  
  104.                    // foreach (var poste in postCopy)
  105.                    // {
  106.                    //     MessageBox.Show(poste.Text);
  107.                    // }
  108.                    
  109.                 }
  110.             }
  111.  
  112.         }
  113.     }
  114. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 4.143 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы