Don Sartain
Don Sartain

Reputation: 617

Type or NameSpace "BlobAttribute" Not Found

I am following along a Pluralsight Tutorial and it's a bit outdated, so I'm trying to fill in the gaps. It says to use a BlobAttribute to set the filename, but I keep getting an error saying that the type or namespace isn't found.

I'm using CSX and I can't for the life of me get it to work. When I copy the line into a C# test function app, it worked just fine. I don't want to switch to that route right now because it's not part of the tutorial and I'm trying to stick with their flow, but they don't explain this either. The Microsoft.Azure.WebJobs using statements were mainly just me experimenting trying to get it to work.

Any ideas how to get the BlobAttribute to work in CSX?

#r "Newtonsoft.Json"
#r "Microsoft.Azure.WebJobs"
#r "Microsoft.Azure.WebJobs.Extensions"

using System;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions;

public class Order
{
public string OrderID {get;set;}
public string ProductID {get;set;}
public string Email{get;set;}
public decimal Price {get;set;}
}

public static void Run(Order myQueueItem, ILogger log, IBinder binder)
{    
log.LogInformation($"C# Queue trigger function processed: 
{myQueueItem.OrderID}");

using(var outputBlob = binder.Bind<TextWriter>(new BlobAttribute($"{myQueueItem.OrderID}.lic")))    
{
    outputBlob.WriteLine($"OrderID: {myQueueItem.OrderID}");
    outputBlob.WriteLine($"ProductID: {myQueueItem.ProductID}");
    outputBlob.WriteLine($"Email: {myQueueItem.Email}");
    outputBlob.WriteLine($"Price: {myQueueItem.Price}");
    outputBlob.WriteLine($"Purchase Date: {DateTime.UtcNow}");

    var md5 = System.Security.Cryptography.MD5.Create();
    var hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(myQueueItem.Email + "secret"));
    outputBlob.WriteLine($"Secret Code: 
{BitConverter.ToString(hash).Replace("-","")}");
    }
}

Upvotes: 4

Views: 4461

Answers (2)

Onkar Vidhate
Onkar Vidhate

Reputation: 103

To solve the same issue in

  1. Visual Studio

Tools > NuGet Package Manager > Package Manager Console > Install-Package Microsoft.Azure.WebJobs.Extensions.Storage -Version 3.0.6

  1. Visual Studio Code

Terminal > cd <Working dir> > dotnet add package Microsoft.Azure.WebJobs.Extensions.Storage

Upvotes: 4

Jerry Liu
Jerry Liu

Reputation: 17800

BlobAttribute locates at assembly Microsoft.Azure.WebJobs.Extensions.Storage, adding reference #r "Microsoft.Azure.WebJobs.Extensions.Storage" could fix.

Besides, see this line

using(var outputBlob = binder.Bind<TextWriter>(new BlobAttribute($"{myQueueItem.OrderID}.lic")))

BlobAttribute requires blob path to be containerName/fileName, hence you may need to add some container before your file like

using(var outputBlob = binder.Bind<TextWriter>(new BlobAttribute($"mycontainer/{myQueueItem.OrderID}.lic")))

Upvotes: 2

Related Questions