c# - Trello 海牛添加附件

标签 c# attachment trello manatee.trello

我正在尝试使用 Manatee API 将附件添加到预先创建的 Trello 卡片。

这就是我创建卡片的方式,我没有遇到任何问题:

        /// <summary>
        ///  This function creates a card on Trello <Board_Name> board, into the list named <List_Name>.
        ///  It creates a card with the title and descrition comming from the function which is called
        /// </summary>
        /// <param name="subject"> This is the subject (Title) of the ticket </param>
        /// <param name="body"> This is the body section (description) of the ticket </param>
        public string createTrelloTicketCard(string subject, string body)
        {
            string cardId = null;
            trelloToken = adminTrelloToken; // define who is creating the card

            Run(() =>
            {
                TrelloProcessor.WaitForPendingRequests = true;
                var board = new Board(<Board_ID>); // board id
                var list = board.Lists[5]; // The sixth list of the board 

                var card = list.Cards.Add(subject); // create a card with the subject from tblTasks
                cardId = card.Id; // get the created card ID
                card.Description = body; // define description from tblTasks
                
                // Add all the IT members to the card
                for (int i = 0; i < numberOfItMembersInBoard; i ++)
                {
                    card.Members.Add(board.Members[i]); 
                }
            });

            return cardId;
        }

这就是我尝试向卡片添加附件的方式。问题出现在这个函数中:

public void InsertAttachementIntoTrelloCard(string cardId, byte[] buffer, string name)
        {
            Run(() =>
            {
                TrelloProcessor.WaitForPendingRequests = true;

                var board = new Board(<Board_ID>); // board id
                
                var list = board.Lists[5]; // The sixth list of the board 
                
                var card = new Card(cardId); // specify the card that the file is going to be attached
                card.Description = "Test3";

                card.Attachments.Add(buffer, name); // Here I get the error
            });
        }

当我尝试附加文件时,出现以这句话开头的错误:

对象引用未设置到对象的实例。

我很确定创建的字节数组是正确的,当我删除该行时,程序结束时没有任何错误。我是不是用错了方法?

这是堆栈跟踪:

ex.Message = "Object reference not set to an instance of an object."

ex.StackTrace = " at Manatee.Trello.Internal.DataAccess.JsonRepository.PrepRequest(IRestRequest request, TrelloAuthorization auth) in e:\Projects\Manatee.Trello\Manatee.Trello\Internal\DataAccess\JsonRepository.cs:line 79 at Manatee.Trello.Internal.DataAccess.JsonRepository.BuildRequest(TrelloAuthorization auth, Endpoint endpoint, IDictionary`2 parameters) in e:\Projects\Manatee.Trello\Manatee.Trello\Internal\DataAccess\JsonRepository.cs:line 74 at Manatee.Trello.Internal.DataAccess.JsonRepository.Execute[T](TrelloAuthorization auth, Endpoint endpoint, IDictionary'2 parameters) in e:\Projects\Manatee.Trello\Manatee.Trello\Internal\DataAccess\JsonRepository.cs:line 46 at Manatee.Trello.AttachmentCollection.Add(Byte[] data, String name) in e:\Projects\Manatee.Trello\Manatee.Trello\AttachmentCollection.cs:line 112 at Live.XmlFax.XmlFaxForm.<>c__DisplayClass8.b__7() in c:\Users\arif.gencosmanoglu\Documents\EnteringC#\Printer Project\XmlFax\XmlFaxForm.cs:line 2035 at Live.XmlFax.XmlFaxForm.Run(Action action) in c:\Users\arif.gencosmanoglu\Documents\EnteringC#\Printer Project\XmlFax\XmlFaxForm.cs:line 1724 at Live.XmlFax.XmlFaxForm.InsertAttachementIntoTrelloCard(String cardId, Byte[] buffer, String name) in c:\Users\arif.gencosmanoglu\Documents\EnteringC#\Printer Project\XmlFax\XmlFaxForm.cs:line 2023 at Live.XmlFax.XmlFaxForm.ReadTicketEmail() in c:\Users\arif.gencosmanoglu\Documents\EnteringC#\Printer Project\XmlFax\XmlFaxForm.cs:line 1981 at Live.XmlFax.XmlFaxForm.cmdItTicket_Click(Object sender, EventArgs e) in c:\Users\arif.gencosmanoglu\Documents\EnteringC#\Printer Project\XmlFax\XmlFaxForm.cs:line 1884

最佳答案

不知道问题出在哪里。堆栈跟踪中指向该点的每条路径都涵盖了所有依赖项,因此不应发生该错误。

请确保您拥有以下最新的 Nuget 包:

  • 海牛.Trello
  • Manatee.Trello.ManateeJson
  • Manatee.Trello.RestSharp

关于c# - Trello 海牛添加附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30201170/

相关文章:

javascript - 如何从 Trello API 检索 token

Trello API : How do I move a card to a different list

c# - 我们可以在 ASP.NET 页面上显示来自 Javascript 警报的超链接吗?

c# - 如何删除 <a :To s:mustUnderstand ="1"> from SOAP Request

ruby-on-rails - ruby rails : Length of Video as a Paperclip Attachment

rest - 如何批量上传 Couchdb 附件?

elasticsearch - 如何使用 Elasticsearch 和 Tire 防止附件存储在 _source 中?

c# - 从外部配置文件设置的 log4net 不起作用

c# - 你调用的对象是空的

javascript - 通过带有 Trello 对象的 javascript 的 Trello API