2

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

Community
  • 1
  • 1
0014
  • 893
  • 4
  • 13
  • 40
  • @GrantWinney yes, I first create a card with no attachments, then i call my function using the created card id, to add an attachment. – 0014 May 12 '15 at 20:59
  • @GrantWinney does this mean I am using the wrong method to add attachment ? – 0014 May 12 '15 at 21:08
  • 2
    I am the creator of Manatee.Trello. Can you update with the stack trace, please? You may have found a hidden bug. I can't see that you're doing anything wrong. This generally works for me (works on my box! haha) – gregsdennis May 13 '15 at 01:55
  • 2
    @GrantWinney, `Attachments` is never null. The collection is created upon Card construction. – gregsdennis May 13 '15 at 02:05
  • I added the stack trace to my post. Thanks for your interests. – 0014 May 13 '15 at 13:20
  • I also added the function which creates the card instance. – 0014 May 13 '15 at 13:38
  • @0014, what version of Manatee.Trello are you using? I'm having trouble replicating the error. – gregsdennis May 13 '15 at 19:06
  • @gregsdennis the installed version is 1.3.0. Should I upgrade it to v 1.4.1 ? – 0014 May 13 '15 at 20:50
  • 1
    @0014, please upgrade and try again. – gregsdennis May 13 '15 at 20:51
  • @gregsdennis I considered upgrading it, however I have a lot of coding done using your API. They wont be effected right ? – 0014 May 13 '15 at 21:00
  • There aren't any breaking changes between those versions. – gregsdennis May 13 '15 at 21:06
  • @gregsdennis Now I even cant create a card hehe. I get error on this line. `var serializer = new ManateeSerializer();` I shall try it later maybe by looking at the latest examples. – 0014 May 13 '15 at 21:14
  • 1
    Please also upgrade Manatee.Trello.ManateeJson and Manatee.Trello.RestSharp – gregsdennis May 13 '15 at 21:16

1 Answers1

1

I don't know where the problem is. Every path to that point in the stack trace has all of the dependencies covered, and that error shouldn't happen.

Please make sure you have the latest of the following Nuget packages:

  • Manatee.Trello
  • Manatee.Trello.ManateeJson
  • Manatee.Trello.RestSharp
gregsdennis
  • 7,218
  • 3
  • 38
  • 71