title: Cannot add attachment to message in MS bot framework: object reference not set to an instance of an object
body: <p>I am writing a facebook bot using MS Bot Framework. I am able to send text replies successfully, but I can't seem to send a picture.</p>
  <p>Microsoft has the following example here - <a href="http://docs.botframework.com/en-us/csharp/builder/sdkreference/attachments.html" rel="nofollow noreferrer">http://docs.botframework.com/en-us/csharp/builder/sdkreference/attachments.html</a></p>
  <pre><code>replyMessage.Attachments.Add(new Attachment()
  {
      ContentUrl = &quot;https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png&quot;,
      ContentType = &quot;image/png&quot;,
      Name = &quot;Bender_Rodriguez.png&quot;      
  });
  </code></pre>
  <p>That code doesn't work for me - it throws this error:</p>
  <blockquote>
  <p>Object reference not set to an instance of an object.</p>
  <p>Bot_Application1.MessagesController.d__0.MoveNext()<br />
  in C:\Users------\Dropbox\code\Bot Application1\Bot<br />
  Application1\Controllers\MessagesController.cs:line 92</p>
  </blockquote>
  <p>Line 92 is where I call the .Attachments.Add() method.</p>
  <p>I've tried to modify the code to make sure it has no null properties inside, so I added non-null Content and ThumbnailUrl, but this also doesn't work (with or without these two parameters). It's exactly the same error as above when calling the Add() method.</p>
  <pre><code>Activity reply3 = activity.CreateReply(&quot;blah&quot;);
  
  Attachment pic = new Attachment();
  pic.ContentUrl = &quot;https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png&quot;;
  pic.ContentType = &quot;image/png&quot;;
  pic.Name = &quot;Bender_Rodriguez.png&quot;;
  pic.Content = &quot;Test&quot;;
  pic.ThumbnailUrl = pic.ContentUrl;
  
  reply3.Attachments.Add(pic);
  
  await connector.Conversations.ReplyToActivityAsync(reply3);
  </code></pre>
  <p>What am I doing wrong?</p>