horatius
horatius

Reputation: 814

Compilation error when trying to reference a CloudBlockBlob in blobstorage triggered function

Here's my function code.

#r "Microsoft.WindowsAzure.Storage.Blob"

public static async Task Run(CloudBlockBlob uploadedVideo, string name, CloudBlockBlob processedVideo, ILogger log)
{
    log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {uploadedVideo.Length} Bytes");
    var fileEntry = new 
    {
        fileName = $"uploaded-videos/{name}",
        fileType = "video",
        correlationId = Guid.NewGuid()
    };
    await processedVideo.StartCopyAsync(uploadedVideo);  
    await uploadedVideo.DeleteIfExistsAsync();
}

and here is my function.json

{
  "bindings": [
    {
      "name": "uploadedVideo",
      "type": "blobTrigger",
      "direction": "in",
      "path": "uploaded-videos/{name}",
      "connection": "AzureWebJobsStorage"
    },
    {
      "type": "blob",
      "name": "processedVideo",
      "path": "processed-videos/{name}-{rand-guid}",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    }
  ]
}

And here is the error that it keeps throwing when I run this function.

2018-09-25T07:34:10.813 [Error] Function compilation error 2018-09-25T07:34:10.982 [Error] BlobTriggerCSharp.csx(2,1): error CS0006: Metadata file 'Microsoft.WindowsAzure.Storage.Blob' could not be found 2018-09-25T07:34:11.040 [Error] BlobTriggerCSharp.csx(4,30): error CS0246: The type or namespace name 'CloudBlockBlob' could not be found (are you missing a using directive or an assembly reference?) 2018-09-25T07:34:11.128 [Error] BlobTriggerCSharp.csx(4,73): error CS0246: The type or namespace name 'CloudBlockBlob' could not be found (are you missing a using directive or an assembly reference?)

Upvotes: 2

Views: 3372

Answers (1)

Jerry Liu
Jerry Liu

Reputation: 17790

There's no Microsoft.WindowsAzure.Storage.Blob assembly, it's a namespace included in Microsoft.WindowsAzure.Storage. The assembly and namespace should be used as below.

#r "Microsoft.WindowsAzure.Storage"

using Microsoft.WindowsAzure.Storage.Blob;

And CloudBlockBlob can't directly get Length property, we have to fetch blob properties first.

await uploadedVideo.FetchAttributesAsync();
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {uploadedVideo.Properties.Length} Bytes");

Upvotes: 5

Related Questions