DavidGouge
DavidGouge

Reputation: 4623

Error when using a precompiled Azure Function with extra methods

I have created a very simple Precompiled function (copied code from tool generated):

public class Foo
    {
        public static async Task<HttpResponseMessage> Run(HttpRequestMessage req)
        {
            //log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");

            // parse query parameter
            string name = req.GetQueryNameValuePairs()
                .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
                .Value;

            // Get request body
            dynamic data = await req.Content.ReadAsAsync<object>();

            // Set name to query string or body data
            name = name ?? data?.name;

            return name == null
                ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
                : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
        }
    }

The dll this resides in is copied to the Function's folder and is linked up in function.json like this:

{
  "scriptFile": "ExternalFunction.dll",
  "entryPoint": "ExternalFunction.Foo.Run",  
  "disabled": false,
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in"
    },
    {
      "name": "res",
      "type": "http",
      "direction": "out"
    }
  ]
}

This all works fine.

What I then wanted to do was add a private method to be called from the Run method, so (baby steps) I added this to the Foo class:

private static string Test()
{
    return "Hello";
}

This results in these errors in the CLI tools:

error AF007: A method matching the entry point name provided in configuration ('ExternalFunction.Foo.Run') does not exist. Your function must contain a single public method, a public method named 'Run', or a public method matching the name specified in the 'entryPoint' metadata property. Function compilation error error AF007: A method matching the entry point name provided in configuration ('ExternalFunction.Foo.Run') does not exist. Your function must contain a single public method, a public method named 'Run', or a public method matching the name specified in the 'entryPoint' metadata property.

Which is a very odd message as surely adding the private static method should have no effect on Functions being able to find the public method specified in function.json?!

Any ideas?

Upvotes: 0

Views: 277

Answers (1)

Fabio Cavalcante
Fabio Cavalcante

Reputation: 12538

This is indeed odd.

I'll work on a repro and open an issue to address the problem if this turns out to be a defect (I'll update the issue or the results of my investigation), but in the meantime, you should be able to create those methods in a different class (static or otherwise) and call that method on that class.

Upvotes: 1

Related Questions