1

So the situation is as follows: I have a azure-botbuilder created chatbot running on a consumption-plan based Azure function. Now I would like to use RestSharp to consume and send requests for REST APIs. However I followed all the instructions to install NuGet Packages for RestSharp and add the requisite dependencies in my project.json, and the "using RestSharp;" import statement inside the code, however for some reason it seems unable to import the library and always gives the error "The type or namespace name 'RestSharp' could not be found (are you missing a using directive or an assembly reference?)"

Heres my project.json:

 {
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.Bot.Builder.Azure": "3.2.5",
        "RestSharp": "105.2.3"

      }
    }
   }
}
coderAce
  • 13
  • 6
  • 1
    I just tried with your project.json file and it worked for me. With the "using RestSharp;" using statement I'm able to create a RestClient instance. Verify that your project.json file in in your root function directory. Try modifying it to force the nuget restore - you should see the nuget restore output in the portal log window, and a project.json.lock file after it is done. – mathewc May 17 '18 at 18:00

1 Answers1

4

If you make an Azure function in version 2.x you need to do this in a different way.

Create a new file called function.proj. This file has an XML structure for importing libraries via Nuget.

Here is my example importing RestSharp.

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="RestSharp" Version="106.6.8"/>
  </ItemGroup>

</Project>

Once you hit save the console will tell you that it is restoring packages. Just wait a minute for it to finish. Mine had a compilation error and Azure restarted the package restore itself and eventually compiled successfully after a minute or so.

Here is where I found this solution: https://stackoverflow.com/a/53053897/4821686

Alan Jones
  • 41
  • 1
  • 4
  • Link to the Microsoft article which has a tons of Developer Reference related to Azure Functions : https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#using-nuget-packages – Purna W Oct 15 '21 at 21:15