title: azure function binding causing multiple events fired
body: <p><strong>Why are we getting duplicate events for the same BlobCreated?</strong></p>
  
  <p>I'm using the following binding in my function app:</p>
  
  <pre><code>        [Blob("%Detach:Output%/{file}", Write)] CloudBlockBlob @out,
  </code></pre>
  
  <p>The only time when I am writing to this output binding is here:</p>
  
  <pre><code>            await @out.UploadTextAsync(xml);
  </code></pre>
  
  <p>I have an event defined like so:</p>
  
  <p><a href="https://i.stack.imgur.com/2rZ5Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2rZ5Q.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/X96KN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X96KN.png" alt="enter image description here"></a></p>
  
  <p>Where <code>Detach:Output</code> env variable is <code>xml-output-with-links-container</code>.</p>
  
  <p>I am consistently getting 2 events for every execution of this function:</p>
  
  <p><a href="https://i.stack.imgur.com/m0KRf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m0KRf.png" alt="enter image description here"></a></p>
  
  <p>The <code>eventTime</code> between the two events are slightly different:</p>
  
  <ul>
  <li>2019-08-05T22:27:06.<strong>5279893Z</strong></li>
  <li>2019-08-05T22:27:06.<strong>5019647Z</strong></li>
  </ul>
  
  <p>We know that they are firing for the same blob because the <code>subject</code> of the event identifies which blob it is:</p>
  
  <pre><code>"subject": "/blobServices/default/containers/xml-output-with-links-container/blobs/tobossthe_awesome_blob.xml",
  </code></pre>
  
  <p>I've tested this manually by uploading a payload to <code>xml-output-with-links-container</code> and have gotten <strong>just 1 event to fire.</strong> Yet, when the function is executed, two events are created. </p>
  
  <p><strong>Why are we getting duplicate events?</strong></p>
  
  <p>Here's the entire function:</p>
  
  <pre><code>{
          [FunctionName("Detach")]
          [StorageAccount("Global:Connection")]
          public static async Task Run(
              [QueueTrigger("%Detach:Trigger%")] DetachJob detach,
              [Blob("%Detach:Input%/{file}", Read)]  CloudBlockBlob @in,
              [Blob("%Detach:Output%/{file}", Write)] CloudBlockBlob @out,
              [Blob("%Detach:Error%/{file}", Write)] CloudBlockBlob fail,
              [Blob("%Detach:Error%/{file}_error", Write)] CloudBlockBlob error,
              [Blob("%Detach:Attachments%", Write)] CloudBlobContainer attachments)
          {
              try
              {
                  var xml = await @in.DownloadTextAsync();
                  var size = ToInt32(GetEnvironmentVariable("Detach:BytesThreshold"));
                  var bigNodes = GetNodesGreaterThan(size, xml);
  
                  foreach (var node in bigNodes)
                  {
                      var ext = GetExtension(node.Value);
                      var path = $"{detach.file}/{node.Key}{ext}.base64";
                      var attachment = attachments.GetBlockBlobReference(path);
                      await attachment.UploadTextAsync(node.Value);
                      xml = xml.Replace(node.Value, path);
                  }
  
                  await @out.UploadTextAsync(xml);
              }
              catch (Exception e)
              {
                  await error.UploadTextAsync(e.ToString());
                  await fail.StartCopyAsync(@in);
              }
          }
      }
  </code></pre>
  
  <p>I was thinking that perhaps the <code>CloudBlockBlob</code> was triggering twice. So I changed the binding to be <code>CloudBlobContainer</code>:</p>
  
  <pre><code>        [Blob("%Detach:Output%", Write)] CloudBlobContainer @out,
  </code></pre>
  
  <p>And updated the respective code:</p>
  
  <pre><code>            var shrink = @out.GetBlockBlobReference(file);
              await shrink.UploadTextAsync(xml);
  </code></pre>
  
  <p>Yet the result stayed the same: I still got 2 events. </p>