4

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("-","")}");
    }
}

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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")))

1 Comment

Thanks! That was it! I tried adding the Microsoft.Azure.WebJobs.Extensions.Storage as a using statement previously, but didn't add the reference first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.