0
votes

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

2
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 Azuresilent
@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
got it. Yeah, recently had the very same scenariosilent
@PiotrStapp Can my solution solve your problem? Have any other doubts?Cindy Pau

2 Answers

1
votes

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");
}
0
votes

You should import the package before using it:

#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.Extensions.Logging;