I've got a strange problem writing an Azure Function. I use HttpClient to get data from a webservice but when I run the function, I get a 'Script compilation failed'. To isolate the problem, I've written an new Azure function in which I just retrieve a HTML response:
using System;
using System.Net.Http;
using System.Threading.Tasks;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
CallHttpClient().Wait;
}
public static async Task CallHttpClient()
{
using (var httpClient = new HttpClient())
{
var str = await httpClient.GetStringAsync("https://www.google.com");
log.Info(str);
}
}
I'm using the Azure Portal. The Invocation log gives me this error:
Exception while executing function: Functions.TestFunctionAsync
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.TestFunctionAsync ---> Microsoft.CodeAnalysis.Scripting.CompilationErrorException : Script compilation failed. at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.CreateFunctionTarget(CancellationToken cancellationToken) at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 343 at async Microsoft.Azure.WebJobs.Script.Description.FunctionLoader`1.GetFunctionTargetAsync[T](Int32 attemptCount) at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\FunctionLoader.cs : 0 at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.GetFunctionTargetAsync() at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 192 at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.InvokeCore(Object[] parameters,FunctionInvocationContext context) at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs : 260 at async Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\FunctionInvokerBase.cs : 171 at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.InvokeAsync[TReflected](Object[] arguments) at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance) at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,ILogger logger,CancellationTokenSou…
using System.Net;
– 4c74356b41using System.Net;
doesn't make any difference. – Robin DijkstraWait
by adding the parens:Wait()
– CrowcoderRun
supports async as in the example linked by @4c74356b41 then you should definitelyawait
instead ofWait()
so as to not block on async. – Crowcoder