System.InvalidOperationException when trying use binding name as parameter in an azure function












0















follow this tutorial chain-azure-functions-data-using-bindings,
when using JavaScript it works, however created a new function app with .net as run time stack, added required cosmos db mappings, when sending GET request with query param like
https://azurefuncurl?code=abc&id=docs
appinsights reveals azure function/host wont start because of System.InvalidOperationException



tried going through official documentation: azure-functions/configInput-Usage, no luck



function.json



{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "cosmosDB",
"name": "bookmark",
"databaseName": "func-io-learn-db",
"collectionName": "Bookmarks",
"connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
"id": "{id}",
"partitionKey": "{id}",
"direction": "in"
}]
}


run.csx



#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log, dynamic bookmark)
{

log.LogInformation("C# HTTP trigger function processed a request.");

string name = req.Query["id"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;

return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}


exception message:



Error indexing method 'Functions.find-bookmark' Unable to resolve binding parameter 'id'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).










share|improve this question



























    0















    follow this tutorial chain-azure-functions-data-using-bindings,
    when using JavaScript it works, however created a new function app with .net as run time stack, added required cosmos db mappings, when sending GET request with query param like
    https://azurefuncurl?code=abc&id=docs
    appinsights reveals azure function/host wont start because of System.InvalidOperationException



    tried going through official documentation: azure-functions/configInput-Usage, no luck



    function.json



    {
    "bindings": [
    {
    "authLevel": "function",
    "name": "req",
    "type": "httpTrigger",
    "direction": "in",
    "methods": [
    "get",
    "post"
    ]
    },
    {
    "name": "$return",
    "type": "http",
    "direction": "out"
    },
    {
    "type": "cosmosDB",
    "name": "bookmark",
    "databaseName": "func-io-learn-db",
    "collectionName": "Bookmarks",
    "connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
    "id": "{id}",
    "partitionKey": "{id}",
    "direction": "in"
    }]
    }


    run.csx



    #r "Newtonsoft.Json"
    using System.Net;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Primitives;
    using Newtonsoft.Json;

    public static async Task<IActionResult> Run(HttpRequest req, ILogger log, dynamic bookmark)
    {

    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["id"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    return name != null
    ? (ActionResult)new OkObjectResult($"Hello, {name}")
    : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
    }


    exception message:



    Error indexing method 'Functions.find-bookmark' Unable to resolve binding parameter 'id'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).










    share|improve this question

























      0












      0








      0








      follow this tutorial chain-azure-functions-data-using-bindings,
      when using JavaScript it works, however created a new function app with .net as run time stack, added required cosmos db mappings, when sending GET request with query param like
      https://azurefuncurl?code=abc&id=docs
      appinsights reveals azure function/host wont start because of System.InvalidOperationException



      tried going through official documentation: azure-functions/configInput-Usage, no luck



      function.json



      {
      "bindings": [
      {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
      "get",
      "post"
      ]
      },
      {
      "name": "$return",
      "type": "http",
      "direction": "out"
      },
      {
      "type": "cosmosDB",
      "name": "bookmark",
      "databaseName": "func-io-learn-db",
      "collectionName": "Bookmarks",
      "connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
      "id": "{id}",
      "partitionKey": "{id}",
      "direction": "in"
      }]
      }


      run.csx



      #r "Newtonsoft.Json"
      using System.Net;
      using Microsoft.AspNetCore.Mvc;
      using Microsoft.Extensions.Primitives;
      using Newtonsoft.Json;

      public static async Task<IActionResult> Run(HttpRequest req, ILogger log, dynamic bookmark)
      {

      log.LogInformation("C# HTTP trigger function processed a request.");

      string name = req.Query["id"];

      string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
      dynamic data = JsonConvert.DeserializeObject(requestBody);
      name = name ?? data?.name;

      return name != null
      ? (ActionResult)new OkObjectResult($"Hello, {name}")
      : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
      }


      exception message:



      Error indexing method 'Functions.find-bookmark' Unable to resolve binding parameter 'id'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).










      share|improve this question














      follow this tutorial chain-azure-functions-data-using-bindings,
      when using JavaScript it works, however created a new function app with .net as run time stack, added required cosmos db mappings, when sending GET request with query param like
      https://azurefuncurl?code=abc&id=docs
      appinsights reveals azure function/host wont start because of System.InvalidOperationException



      tried going through official documentation: azure-functions/configInput-Usage, no luck



      function.json



      {
      "bindings": [
      {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
      "get",
      "post"
      ]
      },
      {
      "name": "$return",
      "type": "http",
      "direction": "out"
      },
      {
      "type": "cosmosDB",
      "name": "bookmark",
      "databaseName": "func-io-learn-db",
      "collectionName": "Bookmarks",
      "connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
      "id": "{id}",
      "partitionKey": "{id}",
      "direction": "in"
      }]
      }


      run.csx



      #r "Newtonsoft.Json"
      using System.Net;
      using Microsoft.AspNetCore.Mvc;
      using Microsoft.Extensions.Primitives;
      using Newtonsoft.Json;

      public static async Task<IActionResult> Run(HttpRequest req, ILogger log, dynamic bookmark)
      {

      log.LogInformation("C# HTTP trigger function processed a request.");

      string name = req.Query["id"];

      string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
      dynamic data = JsonConvert.DeserializeObject(requestBody);
      name = name ?? data?.name;

      return name != null
      ? (ActionResult)new OkObjectResult($"Hello, {name}")
      : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
      }


      exception message:



      Error indexing method 'Functions.find-bookmark' Unable to resolve binding parameter 'id'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).







      azure azure-functions csx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 5:49









      ManiVIManiVI

      891112




      891112
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Simply replace {id} with {Query.id}, have a look at the csx sample.






          share|improve this answer
























          • Thank you, I did not look hard enough

            – ManiVI
            Jan 2 at 18:06



















          1














          for future references
          based on Jerry Liu's recommendation
          ,
          I had to replace id with {Query.id} in function.json like note values in key id & partitionKey



          {
          "type": "cosmosDB",
          "name": "bookmark",
          "databaseName": "func-io-learn-db",
          "collectionName": "Bookmarks",
          "connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
          "id": "{Query.id}",
          "partitionKey": "{Query.id}",
          "direction": "in"
          }


          in run.csx



          create a POCO model class & use it as a param in Run method, below is what entire run.csx looks like



          #r "Newtonsoft.Json"

          using System.Net;
          using Microsoft.Extensions.Primitives;
          using Newtonsoft.Json;
          using System.Text;

          public class Bookmark
          {
          [JsonIgnore]
          public string id {get; set;}

          [JsonProperty(PropertyName ="url")]
          public string URL {get;set;}

          }

          public static HttpResponseMessage Run(HttpRequest req, ILogger log, Bookmark bookmark)
          {
          log.LogInformation("C# HTTP trigger function processed a request.");

          if(bookmark == null)
          {
          string id = req.Query["id"];
          log.LogInformation($"Bookmark item {id} not found");

          return new HttpResponseMessage(HttpStatusCode.NotFound)
          {
          Content = new StringContent($"{id} not found", Encoding.UTF8, "application/json")
          };
          }
          else
          {
          log.LogInformation($"Found item {bookmark.URL}");
          return new HttpResponseMessage(HttpStatusCode.OK)
          {
          Content = new StringContent(JsonConvert.SerializeObject(bookmark), Encoding.UTF8, "application/json")
          };
          }
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001807%2fsystem-invalidoperationexception-when-trying-use-binding-name-as-parameter-in-an%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Simply replace {id} with {Query.id}, have a look at the csx sample.






            share|improve this answer
























            • Thank you, I did not look hard enough

              – ManiVI
              Jan 2 at 18:06
















            1














            Simply replace {id} with {Query.id}, have a look at the csx sample.






            share|improve this answer
























            • Thank you, I did not look hard enough

              – ManiVI
              Jan 2 at 18:06














            1












            1








            1







            Simply replace {id} with {Query.id}, have a look at the csx sample.






            share|improve this answer













            Simply replace {id} with {Query.id}, have a look at the csx sample.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 2 at 6:26









            Jerry LiuJerry Liu

            11.4k11233




            11.4k11233













            • Thank you, I did not look hard enough

              – ManiVI
              Jan 2 at 18:06



















            • Thank you, I did not look hard enough

              – ManiVI
              Jan 2 at 18:06

















            Thank you, I did not look hard enough

            – ManiVI
            Jan 2 at 18:06





            Thank you, I did not look hard enough

            – ManiVI
            Jan 2 at 18:06













            1














            for future references
            based on Jerry Liu's recommendation
            ,
            I had to replace id with {Query.id} in function.json like note values in key id & partitionKey



            {
            "type": "cosmosDB",
            "name": "bookmark",
            "databaseName": "func-io-learn-db",
            "collectionName": "Bookmarks",
            "connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
            "id": "{Query.id}",
            "partitionKey": "{Query.id}",
            "direction": "in"
            }


            in run.csx



            create a POCO model class & use it as a param in Run method, below is what entire run.csx looks like



            #r "Newtonsoft.Json"

            using System.Net;
            using Microsoft.Extensions.Primitives;
            using Newtonsoft.Json;
            using System.Text;

            public class Bookmark
            {
            [JsonIgnore]
            public string id {get; set;}

            [JsonProperty(PropertyName ="url")]
            public string URL {get;set;}

            }

            public static HttpResponseMessage Run(HttpRequest req, ILogger log, Bookmark bookmark)
            {
            log.LogInformation("C# HTTP trigger function processed a request.");

            if(bookmark == null)
            {
            string id = req.Query["id"];
            log.LogInformation($"Bookmark item {id} not found");

            return new HttpResponseMessage(HttpStatusCode.NotFound)
            {
            Content = new StringContent($"{id} not found", Encoding.UTF8, "application/json")
            };
            }
            else
            {
            log.LogInformation($"Found item {bookmark.URL}");
            return new HttpResponseMessage(HttpStatusCode.OK)
            {
            Content = new StringContent(JsonConvert.SerializeObject(bookmark), Encoding.UTF8, "application/json")
            };
            }
            }





            share|improve this answer




























              1














              for future references
              based on Jerry Liu's recommendation
              ,
              I had to replace id with {Query.id} in function.json like note values in key id & partitionKey



              {
              "type": "cosmosDB",
              "name": "bookmark",
              "databaseName": "func-io-learn-db",
              "collectionName": "Bookmarks",
              "connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
              "id": "{Query.id}",
              "partitionKey": "{Query.id}",
              "direction": "in"
              }


              in run.csx



              create a POCO model class & use it as a param in Run method, below is what entire run.csx looks like



              #r "Newtonsoft.Json"

              using System.Net;
              using Microsoft.Extensions.Primitives;
              using Newtonsoft.Json;
              using System.Text;

              public class Bookmark
              {
              [JsonIgnore]
              public string id {get; set;}

              [JsonProperty(PropertyName ="url")]
              public string URL {get;set;}

              }

              public static HttpResponseMessage Run(HttpRequest req, ILogger log, Bookmark bookmark)
              {
              log.LogInformation("C# HTTP trigger function processed a request.");

              if(bookmark == null)
              {
              string id = req.Query["id"];
              log.LogInformation($"Bookmark item {id} not found");

              return new HttpResponseMessage(HttpStatusCode.NotFound)
              {
              Content = new StringContent($"{id} not found", Encoding.UTF8, "application/json")
              };
              }
              else
              {
              log.LogInformation($"Found item {bookmark.URL}");
              return new HttpResponseMessage(HttpStatusCode.OK)
              {
              Content = new StringContent(JsonConvert.SerializeObject(bookmark), Encoding.UTF8, "application/json")
              };
              }
              }





              share|improve this answer


























                1












                1








                1







                for future references
                based on Jerry Liu's recommendation
                ,
                I had to replace id with {Query.id} in function.json like note values in key id & partitionKey



                {
                "type": "cosmosDB",
                "name": "bookmark",
                "databaseName": "func-io-learn-db",
                "collectionName": "Bookmarks",
                "connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
                "id": "{Query.id}",
                "partitionKey": "{Query.id}",
                "direction": "in"
                }


                in run.csx



                create a POCO model class & use it as a param in Run method, below is what entire run.csx looks like



                #r "Newtonsoft.Json"

                using System.Net;
                using Microsoft.Extensions.Primitives;
                using Newtonsoft.Json;
                using System.Text;

                public class Bookmark
                {
                [JsonIgnore]
                public string id {get; set;}

                [JsonProperty(PropertyName ="url")]
                public string URL {get;set;}

                }

                public static HttpResponseMessage Run(HttpRequest req, ILogger log, Bookmark bookmark)
                {
                log.LogInformation("C# HTTP trigger function processed a request.");

                if(bookmark == null)
                {
                string id = req.Query["id"];
                log.LogInformation($"Bookmark item {id} not found");

                return new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                Content = new StringContent($"{id} not found", Encoding.UTF8, "application/json")
                };
                }
                else
                {
                log.LogInformation($"Found item {bookmark.URL}");
                return new HttpResponseMessage(HttpStatusCode.OK)
                {
                Content = new StringContent(JsonConvert.SerializeObject(bookmark), Encoding.UTF8, "application/json")
                };
                }
                }





                share|improve this answer













                for future references
                based on Jerry Liu's recommendation
                ,
                I had to replace id with {Query.id} in function.json like note values in key id & partitionKey



                {
                "type": "cosmosDB",
                "name": "bookmark",
                "databaseName": "func-io-learn-db",
                "collectionName": "Bookmarks",
                "connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
                "id": "{Query.id}",
                "partitionKey": "{Query.id}",
                "direction": "in"
                }


                in run.csx



                create a POCO model class & use it as a param in Run method, below is what entire run.csx looks like



                #r "Newtonsoft.Json"

                using System.Net;
                using Microsoft.Extensions.Primitives;
                using Newtonsoft.Json;
                using System.Text;

                public class Bookmark
                {
                [JsonIgnore]
                public string id {get; set;}

                [JsonProperty(PropertyName ="url")]
                public string URL {get;set;}

                }

                public static HttpResponseMessage Run(HttpRequest req, ILogger log, Bookmark bookmark)
                {
                log.LogInformation("C# HTTP trigger function processed a request.");

                if(bookmark == null)
                {
                string id = req.Query["id"];
                log.LogInformation($"Bookmark item {id} not found");

                return new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                Content = new StringContent($"{id} not found", Encoding.UTF8, "application/json")
                };
                }
                else
                {
                log.LogInformation($"Found item {bookmark.URL}");
                return new HttpResponseMessage(HttpStatusCode.OK)
                {
                Content = new StringContent(JsonConvert.SerializeObject(bookmark), Encoding.UTF8, "application/json")
                };
                }
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 2 at 18:17









                ManiVIManiVI

                891112




                891112






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001807%2fsystem-invalidoperationexception-when-trying-use-binding-name-as-parameter-in-an%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith