I have a Timer Functions (beta version/v2) with that uses the Graph Api and a MySql connection. Everything was working while I had an Http Trigger but now that I've decided to use a Timer Function I'm getting the the error below.
What am I missing? Please let me know. @Jerry Liu, you might know the answer ;)
Error received:
2018-08-10T13:36:17 Welcome, you are now connected to log-streaming service. 2018-08-10T13:37:17 No new trace in the past 1 min(s). 2018-08-10T13:37:23.958 [Information] Script for function 'TimerTriggerMeetingRoom' changed. Reloading. 2018-08-10T13:37:30.447 [Error] run.csx(40,6): error CS1997: Since 'Run(TimerInfo, string, ILogger)' is an async method that returns 'Task', a return keyword must not be followed by an object expression. Did you intend to return 'Task'? 2018-08-10T13:37:30.548 [Information] Compilation failed.
This is my "run.csx" code:
#r "Newtonsoft.Json"
#r "System.Configuration"
#r "System.Data"
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Configuration;
using System.Threading.Tasks;
public static async Task Run(TimerInfo myTimer, string graphToken, ILogger log)
{
var currentTime = DateTime.UtcNow;
var ramsey = new List<Ramsey>();
log.LogInformation("C# HTTP trigger function processed a request.");
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", graphToken);
var json = await client.GetStringAsync("https://graph.microsoft.com/v1.0/me/");
log.LogInformation("C# HTTP trigger function processed a request.");
JObject jResults = JObject.Parse(json);
//log.LogInformation(jResults.ToString());
var result= jResults["value"];
log.LogInformation("value: "+result.ToString());
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(json, Encoding.UTF8, "application/json")
};
}
public class Ramsey
{
public string subject { get; set; }
}
"Function.json":
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */15 * * * *"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "token",
"name": "graphToken",
"resource": "https://graph.microsoft.com",
"identity": "UserFromRequest",
"direction": "in"
}
]
}
This is instead my "functions.proj" file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Mobile.Client" Version="2.0.0"/>
<PackageReference Include="MySql.Data" Version="7.0.7-m61"/>
</ItemGroup>
</Project>