azure function with twilio won't work

Dominik F. Remshardt 1 Reputation point
2021-10-19T16:22:09.7+00:00

I'm trying to deploy a function I found on YT but I fail to compile the function with this error msg:

run.csx(7,7): error CS0246: The type or namespace name 'Twilio' could not be found (are you missing a using directive or an assembly reference?)

My function cotains following project.json

{
"frameworks": {
"net46": {
"dependencies": {
//"Twilio.Twiml": "3.5.0"
"Twilio": "5.0.2"
}
}
}
}

and the run.csx starts with:

r "System.Runtime"

using System.Net;
using System.Text;
using Twilio;
using Twilio.TwiML;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

The funtion is configured as: FUNCTIONS_EXTENSION_VERSION ~1

Any suggestions on how to make things work?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,119 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MayankBargali-MSFT 67,691 Reputation points
    2021-10-20T05:21:51.41+00:00

    @Dominik F. Remshardt As you are using function app version 1.x please refer to this document how to install the package that provides the Twilio bindings.
    I will recommend you to use the function app 3.x and follow function binding twilio that covers the attributes/bindings and the example for usage.

    As per the error message looks like the Twilio namespace was not found on your project i.e. the package was not installed correctly.

    1 person found this answer helpful.
    0 comments No comments

  2. Dominik F. Remshardt 1 Reputation point
    2021-10-20T10:27:39.713+00:00

    I tried using VV.1, 2 and 3 and none of them works

    I keep getting the same error:

    2021-10-20T10:25:23.987 [Information] Compilation failed.
    2021-10-20T10:25:34.922 [Information] Executing 'Functions.Twilio' (Reason='This function was programmatically called via the host APIs.', Id=0c2dd7fa-835a-49c2-9504-7769b4786e00)
    2021-10-20T10:25:34.923 [Information] Package references have been updated.
    2021-10-20T10:25:34.924 [Information] Restoring packages.
    2021-10-20T10:25:34.951 [Information] Starting packages restore
    2021-10-20T10:25:36.075 [Information] C:\local\Temp\403c3d8b-c369-4941-ba36-9ea44ce28b07\function.proj(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
    2021-10-20T10:25:36.148 [Information] Packages restored.
    2021-10-20T10:25:36.261 [Warning] You may be referencing NuGet packages incorrectly. The file 'C:\home\site\wwwroot\Twilio\project.json' should not be used to reference NuGet packages. Try creating a 'function.proj' file instead. Learn more: https://go.microsoft.com/fwlink/?linkid=2091419
    2021-10-20T10:25:36.261 [Warning] You may be referencing NuGet packages incorrectly. The file 'C:\home\site\wwwroot\Twilio\project.json' should not be used to reference NuGet packages. Try creating a 'function.proj' file instead. Learn more: https://go.microsoft.com/fwlink/?linkid=2091419
    2021-10-20T10:25:36.261 [Warning] You may be referencing NuGet packages incorrectly. The file 'C:\home\site\wwwroot\Twilio\project.json' should not be used to reference NuGet packages. Try creating a 'function.proj' file instead. Learn more: https://go.microsoft.com/fwlink/?linkid=2091419
    2021-10-20T10:25:36.262 [Warning] You may be referencing NuGet packages incorrectly. The file 'C:\home\site\wwwroot\Twilio\project.json' should not be used to reference NuGet packages. Try creating a 'function.proj' file instead. Learn more: https://go.microsoft.com/fwlink/?linkid=2091419
    2021-10-20T10:25:36.262 [Warning] You may be referencing NuGet packages incorrectly. The file 'C:\home\site\wwwroot\Twilio\project.json' should not be used to reference NuGet packages. Try creating a 'function.proj' file instead. Learn more: https://go.microsoft.com/fwlink/?linkid=2091419
    2021-10-20T10:25:36.263 [Warning] You may be referencing NuGet packages incorrectly. The file 'C:\home\site\wwwroot\Twilio\project.json' should not be used to reference NuGet packages. Try creating a 'function.proj' file instead. Learn more: https://go.microsoft.com/fwlink/?linkid=2091419
    2021-10-20T10:25:36.289 [Error] Function compilation errorMicrosoft.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 : 321at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at async Microsoft.Azure.WebJobs.Script.Description.FunctionLoader`1.GetFunctionTargetAsyncT at D:\a\1\s\src\WebJobs.Script\Description\FunctionLoader.cs : 55at 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 : 193
    2021-10-20T10:25:36.351 [Error] run.csx(3,1): error CS0006: Metadata file 'Twilio' could not be found
    2021-10-20T10:25:36.409 [Error] run.csx(4,1): error CS0006: Metadata file 'Microsoft.Azure.WebJobs.Extensions.Twilio' could not be found
    2021-10-20T10:25:36.460 [Error] run.csx(9,7): error CS0246: The type or namespace name 'Twilio' could not be found (are you missing a using directive or an assembly reference?)
    2021-10-20T10:25:36.508 [Error] run.csx(10,7): error CS0246: The type or namespace name 'Twilio' could not be found (are you missing a using

    0 comments No comments