Search code examples
c#twilioasp.net-core-2.0twilio-twiml

Why can't my ASP.NET Core 2 method return TwiML?


I have an ASP.NET Core 2 application and I'm trying to forward a call made to a Twilio number to another number. When I try to return TwiML I get an error that says:

"Non-invocable member 'TwiML' cannot be used like a method."

Here's the method:

[HttpPost]
public TwiMLResult ForwardCall(string called)
{
   var response = new VoiceResponse();
   response.Dial(newNumber);

   return TwiML(response);
}

The error happens here:

return TwiML(response);

All the code examples I've seen tell me to return the TwiML this way but for some reason, I'm unable to.


Solution

  • The problem was that the controller was not inheriting from TwilioController. Once I had my controller inherit from TwilioController the error went away.