0

I'm trying to run a function from a dll file but I'm getting this error:

2018-02-17T12:51:41.403 [Error] Exception while executing function: Functions.PreCompiledHttpTrigger. Microsoft.Azure.WebJobs.Script: One or more errors occurred. System.Web.Http: The request does not have an associated configuration object or the provided configuration was null.

using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace CompiledAzureFunctions
{
public class Utility
{
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req)
{
    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    if (name == null)
    {
        // Get request body
        dynamic data = await req.Content.ReadAsAsync<object>();
        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);
}
}
}

function.json

{
  "scriptFile": "bin/CompiledAzureFunctions.dll",
  "entryPoint": "CompiledAzureFunctions.Utility.Run",
  "bindings": [
    {
      "authLevel": "anonymous",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ],
  "disabled": false
}
Jan_V
  • 4,244
  • 1
  • 40
  • 64
thatsIT
  • 2,085
  • 6
  • 29
  • 43
  • This looks similar to one of the default templates from "File ... New..." Try creating a new Function project and a Function from the templates, deploy it and run it. I'm not sure how you created this one from the start... – Chris Pietschmann Feb 17 '18 at 14:32
  • Yes this is a default template. I copied the .dll that to the functions bin folder in 'App service editor'. This is only a experiment / testing. – thatsIT Feb 17 '18 at 15:44
  • The dll file will be produced automatically, so I am not clear why you want to copy .dll to function and how do you copy it to dll. Did your dll file is related to the function and where did it transfer. You could use external assemblies like [this](https://stackoverflow.com/questions/36559509/how-do-i-use-external-assemblies-with-microsoft-azure-function-apps) – Joey Cai Feb 19 '18 at 05:59
  • I was watching a tutorial and he did it like that, but I got that error. However it's not any important that this will run since I can publish it as usually. – thatsIT Feb 21 '18 at 21:10
  • The code above doesn't seem to be the code being executed, based on the exception. What bin folder did you copy the assembly to? A folder in the function directory? or the root? If the root, you need to have a path relative to the function folder (e.g. ../bin/assembly.dll). This is also the old model for precompiled assemblies. We support a model using attributes that makes this process a little simpler. Creating an Azure Functions using the VS project gives you that by default. – Fabio Cavalcante Feb 23 '18 at 21:17

0 Answers0