0

I am working on SharePoint webhook using function app. I am using Using Azure Functions with SharePoint webhooks[Reference]. I created a function on Microsoft azure using function app, in which I got the default code as follow:

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
 {
    log.LogInformation("C# HTTP trigger function processed a request.");
    string name = req.Query["name"];
    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");
}

Then I replaced the given code of function with the code given in the run() of the reference. I tried to run the program but it giving me the following error:

2020-02-05T07:40:16.362 [Error] Function compilation error
Microsoft.CodeAnalysis.Scripting.CompilationErrorException : Script compilation failed.
   at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.CreateFunctionTarget(CancellationToken cancellationToken) at D:\a\1\s\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 314
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Script.Description.FunctionLoader`1.GetFunctionTargetAsync[T](Int32 attemptCount) at D:\a\1\s\src\WebJobs.Script\Description\FunctionLoader.cs : 55
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.GetFunctionTargetAsync(Boolean isInvocation) at D:\a\1\s\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 183
2020-02-05T07:40:16.580 [Warning] run.csx(11,62): warning CS0618: 'TraceWriter' is obsolete: 'Will be removed in an upcoming version. Use Microsoft.Extensions.Logging.ILogger instead.'
2020-02-05T07:40:16.632 [Error] run.csx(16,34): error CS1061: 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs' and no accessible extension method 'GetQueryNameValuePairs' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)
2020-02-05T07:40:16.757 [Error] run.csx(47,19): error CS1061: 'CloudQueue' does not contain a definition for 'CreateIfNotExists' and no accessible extension method 'CreateIfNotExists' accepting a first argument of type 'CloudQueue' could be found (are you missing a using directive or an assembly reference?)
2020-02-05T07:40:16.821 [Error] run.csx(52,19): error CS1061: 'CloudQueue' does not contain a definition for 'AddMessage' and no accessible extension method 'AddMessage' accepting a first argument of type 'CloudQueue' could be found (are you missing a using directive or an assembly reference?)
2020-02-05T07:40:16.918 [Error] Executed 'Functions.HttpTrigger1' (Failed, Id=36875311-6d8e-496a-989b-1ac16ce39f5a)
Script compilation failed.

I don't know what have I done wrong while following the steps given in the reference. How can I rectify this error and setup a function to get notification of SharePoint site?

Abhi Singh
  • 321
  • 3
  • 14

1 Answers1

0

The example you are referring is for Function run-time V1 and when you create a new function from the it will point to runtime V3. In order to run that same as is you need to downgrade you function runtime to V1 and use the code as it is from the document

In order to downgrade function runtime to v1 , You need to browser to Azure Function Portal --> Platform Features --> Configuration

point FUNCTIONS_EXTENSION_VERSION to ~1 and delete FUNCTIONS_WORKER_RUNTIME App setting.

Ref doc: https://learn.microsoft.com/en-us/azure/azure-functions/set-runtime-version

Community
  • 1
  • 1
Ketan
  • 1,530
  • 7
  • 16