Azure-docs: run.csx - error CS0246: The type or namespace name 'Twilio' could not be found

Created on 16 Oct 2018  Â·  11Comments  Â·  Source: MicrosoftDocs/azure-docs

Hello.

I've trying to compile examples of twilio voice and sms applications, and even just adding the reference of twilio in the code and without using it, sends the error of the topic.

The documentation says that in the web plataform just need to reference i the library and is gonna works, but the problem stills appears.

I've added too the file "project.json" with this content:


{
"frameworks": {
"net46":{
"dependencies": {
"Twilio": "5.0.2"
}
}
}

}

The content of the file run.csx is:


r "System.Runtime"

using System.Net;
using System.Text;
using Twilio.TwiML;

public static async Task Run(HttpRequestMessage req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

var data = await req.Content.ReadAsStringAsync();
var formValues = data.Split('&')
    .Select(value => value.Split('='))
    .ToDictionary(pair => Uri.UnescapeDataString(pair[0]).Replace("+", " "), 
                  pair => Uri.UnescapeDataString(pair[1]).Replace("+", " "));

// Perform calculations, API lookups, etc. here

// Insert spaces between the numbers to help the text-to-speech engine
var number = formValues["From"]
    .Replace("+", "")
    .Aggregate(string.Empty, (c, i) => c + i + ' ')
    .Trim();

var response = new VoiceResponse()
    .Say($"Your phone number is {number}");
var twiml = response.ToString();
twiml = twiml.Replace("utf-16", "utf-8");

return new HttpResponseMessage
{
    Content = new StringContent(twiml, Encoding.UTF8, "application/xml")
};

}


Errors:

2018-10-16T20:30:03.658 [Error] 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?)
2018-10-16T20:30:03.833 [Error] run.csx(28,24): error CS0246: The type or namespace name 'VoiceResponse' could not be found (are you missing a using directive or an assembly reference?)


Thanks in advance for the help.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 azure-functionsvc cxp product-issue triaged

All 11 comments

@danielhzrivera Thank you very much for your interest in Azure products and services. To help you further, may I have a link to the documentation or samples you are attempting to reference. Thank you.

And I think you your run.csx should look something more like, in the case of SMS:

r "Newtonsoft.Json"

r "Twilio.Api"

using System;
using Newtonsoft.Json;
using Twilio;

Hello Mike.

Thanks for your answer.

These are the references that I've been using.

https://www.twilio.com/docs/usage/tutorials/serverless-webhooks-azure-functions-and-csharp?code-sample=code-receive-sms-with-c-azure-functions&code-language=C%23&code-sdk-version=5.x#write-a-function-to-respond-to-sms-messages

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-twilio

https://youtu.be/zrBAyKhoF7E

I've tried each example, and the azure function fails even just adding the twilio reference.

Thanks again for the help.

@danielhzrivera Version 1.x or 2.x for Azure Functions? There was a recent 2.x release for Azure Functions that introduce quite a few breaking changes. This might be part of that. Have you or can you try this in a 1.x environment. Meanwhile, I will investigate the latest 2.x status. Thanks, Mike

@mike-urnun-msft Are you able to provide some input regarding this issue?

Hey @danielhzrivera Were you able to install the necessary dependencies (Twilio & VoiceResponse) OK? Are you still getting the same error messages even though you've installed the dependencies? Please review this table and ensure the necessary packages are installed properly according to their version specs.

Hello Again.

I've been working with visual studio and ngrok to test the functions and
the examples works locally.

I'm still not publishing on cloud.

I will update if I have troubles after publish the functions.

Regards

@danielhzrivera We will now proceed to close this thread. If there are further questions regarding this matter, please comment and we will gladly continue the discussion.

@Mike-Ubezzi-MSFT , having the same issue - how do I go about creating a 1.x Function App? I don't see that option anywhere in the create or manage dialogs.

has this issue been resolved? What do we do? I have the same issue running Twilio's sample code today. Any workarounds to use it in 3.x Function Apps? or do we have to live with running it on 1.x?

@ramkumar-b I don't see support for version 3.x but you could create a new issue and ask the question. The integration engineering team will be able to respond with updated information. I only see support for version 1.x and 2.x.

Was this page helpful?
0 / 5 - 0 ratings