Senkwe
Senkwe

Reputation: 2256

The type or namespace name 'Twilio' could not be found

So I've got a dotnet core app, I'd like to use Twilio so I performed the following from the command line.

dotnet add package Twilio

All went well, no errors. It adds version 5.1.1 of Twilio packages. But building the app now gives me

The type or namespace name 'Twilio' could not be found

I'm running .Net core version 1.1 with the equivalent 1.0.1 SDK.

Any ideas?

Upvotes: 4

Views: 2004

Answers (2)

PowerMan2015
PowerMan2015

Reputation: 1418

Ive just had this problem with a core 2.2 project. It turns out i needed an additional using statement of:

using Twilio.Types;

Visual studio wasnt providing any suggestions when it was referenced as follows:

twilio.Types.PhoneNumber("xx");

Changing the reference to the below prompted a new using suggestion from Visual Studio:

PhoneNumber("xx");

Hope this helps someone

Upvotes: 0

Shaun Luttin
Shaun Luttin

Reputation: 141552

Did you restore? The following works for me.

dotnet new console
dotnet add package Twilio
dotnet restore              <---- We need to restore after adding a package.
dotnet build

Program.cs

using Twilio;

class Program
{
    static void Main(string[] args)
    {
        TwilioClient.SetUsername("foo");
    }
}

DotNetCoreTwilio.csproj

<Project Sdk="Microsoft.NET.Sdk">                         
  <PropertyGroup>                                         
    <OutputType>Exe</OutputType>                          
    <TargetFramework>netcoreapp1.1</TargetFramework>      
  </PropertyGroup>                                        
  <ItemGroup>                                             
    <PackageReference Include="Twilio" Version="5.1.1" /> 
  </ItemGroup>                                            
</Project>                                                

Upvotes: 3

Related Questions