0

Somehow I cannot use package Microsoft.Azure.Storage.blob in Azure Function v2 using csx.

In extension.proj I have following:

<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.0" />

In csx file I have:

using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;

And I have error:

run.csx(7,23): error CS0234: The type or namespace name 'Storage' does not exist in the namespace 
'Microsoft.Azure' (are you missing an assembly reference?)

Full code is on GitHub: https://github.com/ptrstpp950/cognitive-service-azure-function

Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • I keep telling people this here... ;) If you can do yourself one favor, switch to authoring your Functions in a proper IDE and upload them in compiled form to Azure – silent Oct 15 '19 at 14:58
  • @silent I cannot. I have to make them editable in browser for workshop. I switched to NodeJS. It works like a charm in this case :) – Piotr Stapp Oct 15 '19 at 15:00
  • got it. Yeah, recently had the very same scenario – silent Oct 15 '19 at 15:02
  • @PiotrStapp Can my solution solve your problem? Have any other doubts? – Cindy Pau Oct 16 '19 at 08:53

2 Answers2

1

1.Are you sure of the extension.proj you are using?

From your code I know you are writing on the portal. So you should create function.proj instead of extension.proj on portal.

2. I see you write <PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.0" /> in .proj file. So you should use #r "Microsoft.WindowsAzure.Storage" instead of using Microsoft.WindowsAzure.Storage

Below is the code of my function.proj, things works fine on my side. For more details, have a look of this Offical doc.(All of the solution is based on you are using function 2.x. If you are using function 1.x. It is not the same.)

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

    <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.0" />
    </ItemGroup>
</Project>

enter image description here

Code of my .crx file:

#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.Azure.Storage.Blob;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    return name != null
        ? (ActionResult)new OkObjectResult($"Hello, {name}")
        : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • Why `#r Microsoft.WindowsAzure.Storage` instead of `Microsoft.Azure.Storage.Blob` ? – Piotr Stapp Oct 16 '19 at 09:06
  • @PiotrStapp For framework assemblies, add references by using the #r "AssemblyName" directive. First add references and then using. Maybe you need a detailed description of using the .crx file: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp – Cindy Pau Oct 16 '19 at 09:19
  • My description may have a problem, I mean you have to use #r "xxx" to refer to it instead of using `using` directly. This is not the same as in Visual Studio. – Cindy Pau Oct 16 '19 at 11:02
0

You should import the package before using it:

#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.Extensions.Logging;
Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90