0

Azure API Management is with a response "System.NullReferenceException: Object reference not set to an instance of an object."

MyFunction.Run(HttpRequest req, ILogger log) in MyFunction.cs:line 61

method signature

public async Task Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log)

Sorry everybody, I newer in Azure APIM!

When I send JSON below in request body to c# azure function API, everything works as well!!

{
    "Id":40,
    "status":"Doing",
    "startedDateTime":"2019-10-17T17:50:44.1314885Z"
}

But when I sending it thru the Azure API Management to serverless azure function API Microservice, I'm getting the error message "Object reference not set to an instance of an object."

My Azure function has only APIM Key into headers and no more things; I just created APIM consumption for use as an endpoint, I have only CORS policy and trying to use for a test, but I got the same problem with

<policies>
    <inbound>
        <base />
        <choose>
            <when condition="@(context.Request.Body != null)">
                <set-body template="liquid">
                    <value>@(context.Request.Body.As<JObject>(preserveContent: true).Value<string>())</value>
                </set-body>
            </when>
        </choose>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

Someone can help me? What would be the same solution?

  • I'm using azure consumption mode – Marcelo Nascimento Jul 04 '20 at 18:36
  • 1
    More information is needed: What is your APIM doing, whats your yaml file, do you have any policies, what is your function doing? f.e. are you using headers in the request which are not piped through APIM and needed in the function app? – Martin Jul 04 '20 at 18:56
  • I'd edit my post to add information about my policies, unfortunately, I'm newer in APIM; In Header, I sent only Ocp-Apim-Subscription-Key as a token for APIM, no more! so and about APIM YAML, I confess that I can't found, could you know tell where is it? – Marcelo Nascimento Jul 04 '20 at 20:24
  • Sorry late answer. Question is how did you registered your API in APIM? (GET/POST/..., how did you specify your api with a swagger/yaml file?) Is it possible to send GET requests through APIM and read the content? – Martin Jul 05 '20 at 20:34
  • [SOLVED] It's working now use method POST instead of method GET for azure function. However, it's look liking azure APIM consumptions isn't preparing for tracing objects into request body for method get by this moment. If someone knows how to use method get for this or both get and post in azure function, will be welcome for this comment! [enter image description here][1] [1]: https://i.stack.imgur.com/LmdXf.png – Marcelo Nascimento Jul 06 '20 at 21:08
  • @Martin is possible to send Get request but is not possible to send any "Body" to method Get verb request trough APIM consumption, that's why I found this issue. when I changed it to method Post, everything works, good!! – Marcelo Nascimento Jul 06 '20 at 21:11

0 Answers0