我正在尝试使用 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/