I'm trying to integrate Twilio with my ASP.NET Core MVC Application but in the controller, I'm getting an error in my return statement.
**Cannot implicitly convert type 'System.Web.Mvc.ContentResult' to 'Microsoft.AspNetCore.Mvc.ContentResult' **
Controller Code
using Microsoft.AspNetCore.Mvc;
using System.Configuration;
using Twilio;
using Twilio.AspNet.Mvc;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.TwiML;
namespace TwilioTesting.Controllers
{
public class SMSController : TwilioController
{
public ContentResult Index()
{
var accountSid = "AC12345678";
var authToken = "12345678";
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber(" 92313887998");
var from = new PhoneNumber(" 19898980625");
var message = MessageResource.Create(
to: to,
from: from,
body: "Message from Kamran");
return Content(message.Sid);
}
}
}
CodePudding user response:
You have a using Twilio.AspNet.Mvc;
import which is not for .NET Core & is for ASP.NET MVC. It is unexpectedly importing in System.Web.Mvc.ContentResult
which is conflicting with the import of Microsoft.AspNetCore.Mvc.ContentResult
.
Remove it and replace it with using Twilio;
.