I am trying to add an attachment to a pre-created Trello card using Manatee API.
This is how I create the card, I have no problems with it:
/// <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;
}
This is how I try adding attachment to the card. The problem occurs in this function:
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
});
}
When I try attaching the file I get an error starting with this sentence:
Object reference not set to an instance of an object.
I am pretty sure the created byte array is correct and when I remove that line the program ends without any errors. Am I using the wrong method ?
Here is the Stack Trace:
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