Please excuse our look. We're just getting started here.

Want to learn more about Twilio Forums? Check out our FAQ page here.

Error: Twilio.Exceptions.AuthenticationException: 'Username can not be null'

edited January 4 in Twilio Community

Hello everyone! I'm trying to use Twilio for an app that I'm working on, but I'm getting an error "Twilio.Exceptions.AuthenticationException: 'Username can not be null'". I'm using C# ASP.NET and Xamarin. Here's the part of the code:

// Find your Account SID and Auth Token at

                // and set the environment variables. See

        string accountSid = Environment.GetEnvironmentVariable("************"); (obviously I'll censor some sensible information)

        string authToken = Environment.GetEnvironmentVariable("************");

                string mensagem = "******";

        string numeroTelefone = "+55" + DataEntry.Text;

        TwilioClient.Init(accountSid, authToken);

        var message = MessageResource.Create(

          body: mensagem,

          from: new Twilio.Types.PhoneNumber("********"),

          to: new Twilio.Types.PhoneNumber(numeroTelefone)


do you guys have any ideas what may be causing the error? do I need to settle my Twilio username and password in the code, or just ID and authToken should work? Thanks if you took your time to answer me!

EDIT: Solved. I was trying to use my ID as an environment variable but forgot to set it first.


If this is an emergency, please contact Twilio Support. This is not an official Support channel.
Have an urgent question?
Please contact Twilio Support. This is not an official Support channel.
Contact Support