0

I have this

code

It has http trigger and time trigger.

Now when I run the azure function it gives me this

error

What am I doing wrong ?

(EDIT)
Just updated my visual studio and build tools to latest version and it solve the problem.

7
  • Invalid Question Description. Provide what you have tried, got any error message and the question isn't clear what the requirement is! Otherwise, the question will be closed. Commented Jan 12, 2023 at 11:21
  • The way you created the Http Trigger, is the same for Creating any other triggers where you have to select the type of trigger required in the creation process and configure accordingly. MS Doc Commented Jan 12, 2023 at 11:25
  • You just do! Right click, add New Azure Function and select timer trigger. Commented Jan 12, 2023 at 11:27
  • 1
    do not post images, instead give the text of your code. See SO guideline on Why should I not upload images of code? Commented Jan 12, 2023 at 12:10
  • So, you need to write both the triggers in same function code? Commented Jan 12, 2023 at 12:42

2 Answers 2

1

Turns out my visual studio and build tools were outdated.
So I just updated it the latest version and it solved my issue. Thank you for all the answers.

Sign up to request clarification or add additional context in comments.

Comments

0

I have taken .NET 6 Azure Functions v4 and made the Function 2 (Timer Trigger as static) and changed the Run method name to Run2, it is working successfully as you can see below screenshot:

enter image description here

And in 2nd practical, tried with your Timer Trigger Code Provided, made changes as did in above with Authorization Level as Function and got the successful result:

enter image description here

Function Code:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace KrishNet6FunApp1040
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] 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;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);
        }


        [FunctionName("TimerTriggerCSharp")]
        public static void Run2([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
        {
            if (myTimer.IsPastDue)
            {
                log.LogInformation("Timer is running late!");
            }
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

2 Comments

cant view your images
Hello @khert, I can see the images. Can you refresh and check again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.