title: Custom bindings in Azure Function not getting resolved
body: <p>I'm trying to create my own custom binding for Azure Functions.
  This work is based on 2 wiki articles concerning this feature:
  <a href="https://github.com/Azure/azure-webjobs-sdk/wiki/Creating-custom-input-and-output-bindings" rel="noreferrer">https://github.com/Azure/azure-webjobs-sdk/wiki/Creating-custom-input-and-output-bindings</a>
  and
  <a href="https://github.com/Azure/WebJobsExtensionSamples" rel="noreferrer">https://github.com/Azure/WebJobsExtensionSamples</a></p>
  <p>For a sample project, I'm referring to the <a href="https://github.com/Azure/WebJobsExtensionSamples" rel="noreferrer">Azure Functions/WebJobs binding extension sample project</a>.
  This project is based on the .NET Framework 4.6.</p>
  <p>I want my own custom binding to work with Azure Functions v2, so I'm targetting NetStandard2 in all of my projects.</p>
  <p>In the sample project, I see the binding extension is getting loaded when starting the local emulator.</p>
  <blockquote>
  <p>[3-1-2019 08:48:02] Loaded binding extension 'SampleExtensions' from 'referenced by: Method='FunctionApp.WriterFunction.Run', Parameter='sampleOutput'.'</p>
  </blockquote>
  <p>However, I never see this line appearing when running my own binding extension.</p>
  <p>What I've done is the following.
  First, I've created a new attribute.</p>
  <pre><code>[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
  [Binding]
  public class MySimpleBindingAttribute : Attribute
  {
      /// &lt;summary&gt;
      /// Path to the folder where a file should be written.
      /// &lt;/summary&gt;
      [AutoResolve]
      public string Location { get; set; }
  }
  </code></pre>
  <p>And a rather simple extension class</p>
  <pre><code>public class MySimpleBindingExtension : IExtensionConfigProvider
  {
      public void Initialize(ExtensionConfigContext context)
      {
          var rule = context.AddBindingRule&lt;MySimpleBindingAttribute&gt;();
          rule.BindToInput&lt;MySimpleModel&gt;(BuildItemFromAttribute);
      }
  
      private MySimpleModel BuildItemFromAttribute(MySimpleBindingAttribute arg)
      {
          string content = default(string);
          if (File.Exists(arg.Location))
          {
              content = File.ReadAllText(arg.Location);
          }
  
          return new MySimpleModel
          {
              FullFilePath = arg.Location,
              Content = content
          };
      }
  }
  </code></pre>
  <p>And of course, the model.</p>
  <pre><code>public class MySimpleModel
  {
      public string FullFilePath { get; set; }
      public string Content { get; set; }
  }
  </code></pre>
  <p>From what I've been reading on the wiki I think this should be enough to use it in my Azure Functions project.
  The Function looks like this.</p>
  <pre><code>[FunctionName(&quot;CustomBindingFunction&quot;)]
  public static IActionResult Run(
      [HttpTrigger(AuthorizationLevel.Anonymous, &quot;get&quot;, &quot;post&quot;, Route = &quot;{name}&quot;)]
      HttpRequest req,
      string name,
      [MySimpleBinding(Location = &quot;%filepath%\\{name}&quot;)]
      MySimpleModel simpleModel)
  {
      return (ActionResult) new OkObjectResult(simpleModel.Content);
  }
  </code></pre>
  <p>When running this in the emulator I'm seeing the following error &amp; warning messages.</p>
  <blockquote>
  <p>[3-1-2019 08:51:37] Error indexing method 'CustomBindingFunction.Run'</p>
  <p>[3-1-2019 08:51:37] Microsoft.Azure.WebJobs.Host: Error indexing method 'CustomBindingFunction.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'simpleModel' to type MySimpleModel. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).</p>
  <p>[3-1-2019 08:51:37] Function 'CustomBindingFunction.Run' failed indexing and will be disabled.</p>
  <p>[3-1-2019 08:51:37] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).</p>
  </blockquote>
  <p>Now, this message makes sense in a WebJob scenario, but for an Azure Function you con't have a place to set something up in the startup code.
  Invoking the Function throws the following message.</p>
  <blockquote>
  <p>[3-1-2019 08:53:13] An unhandled host error has occurred.</p>
  <p>[3-1-2019 08:53:13] Microsoft.Azure.WebJobs.Host: 'CustomBindingFunction' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?.</p>
  </blockquote>
  <p>I've read something about adding an <a href="https://blog.wille-zone.de/post/azure-functions-iextensionconfigprovider-resolution-and-instantiates/" rel="noreferrer"><code>extensions.json</code> file and use the <code>AzureWebJobs_ExtensionsPath</code> (for v1)</a>, but those don't appear do do anything (or I've done something wrong).</p>
  <p>Any ideas on how to proceed?</p>
  <p>For completeness sake, here are my current references to NuGet packages.</p>
  <pre><code>&lt;PackageReference Include=&quot;Microsoft.Azure.WebJobs&quot; Version=&quot;3.0.3&quot; /&gt;
  &lt;PackageReference Include=&quot;Microsoft.NET.Sdk.Functions&quot; Version=&quot;1.0.24&quot; /&gt;
  &lt;PackageReference Include=&quot;Newtonsoft.Json&quot; Version=&quot;11.0.2&quot; /&gt;
  </code></pre>