简体   繁体   中英

Precompiled Azure Function Output to Blob Storage receiving 500 Internal Server Error

The final output of my C# Precompiled Azure Function is to write to a blob storage as a JSON file. Am I writing to the Blob storage wrong? I hit the breakpoints set on the curly brackets at to the end of the function and it looks like it exits the function. Around 20 seconds later I get the exception:

Exception while executing function: ServiceBusTriggeredProcessAccepted. Microsoft.Azure.WebJobs.Host: Error while handling parameter outboundStringForBlobStorage after function returned:. Microsoft.WindowsAzure.Storage: The remote server returned an error: (500) Internal Server Error.

The Azure Function is a Service Bus triggered event. After processing fails the Service Bus queued item auto-increments and retries, a total of 10 times, before it's moved to the dead-letter queue. It should be noted the objects are large enough in size that regular Queue's are too small for them.

public class SomeObject
{
    //15 Properties all string and boolean
    public string Attachment{ get; set;}
    public string AnotherProperty{ get; set;}
    public bool IsConditionMet { get; set; }
    //Maybe these aren't needed now since it's blob storage but it's part of the object currently
    public string PartitionKey { get; set; }
    public string RowKey { get; set; }
}

[FunctionName("ServiceBusTriggeredProcessAccepted")]
public static void Run([ServiceBusTrigger("accepted")]
 SomeObject someObject,
 TraceWriter log,
 [Blob("accepted-attachments/{Attachment}", FileAccess.Read)] Byte[] blobContent
 , [Blob("accepted-sent/{rand-guid}.json")] out string outboundStringForBlobStorage 
 )
{
    someObject.PartitionKey = "email";
    someObject.RowKey = Guid.NewGuid().ToString();
    //Business Logic to execute here
    SomeService.SomeFunctionToSendBlobFile(someObject, blobContent)   
    outboundStringForBlobStorage  = JsonConvert.SerializeObject(someObject);
}

I am using: Azure Functions SDK NuGet Package 1.0.21
Microsoft.Azure.Webjobs 2.2.0
WindowsAzure.ServiceBus 5.0.0
DotNetFramework 4.6.1
Windows Azure Storage Emulator 5.8.0.0
Runtime Version=1.0.11702.0

Does the serialization have to be sanitized somehow? I haven't had to sanitize in the past but the data in that object has changed and that is when the problems started to occur. I would expect that the file to get written to the blob storage immediately or return the exception immediately and not 20 seconds after exiting the function.

The error may have nothing to do with serialization, let's focus on this line.

Microsoft.WindowsAzure.Storage: The remote server returned an error: (500) Internal Server Error.

If I understand correctly, the blob input and output both connect with Azure Storage Emulator. There's sth wrong in v5.8 Emulator failing blob writing . Install latest Emulator (v5.9 right now) could get rid of the problem.

And also note that Runtime Version=1.0.11702.0 means the CLI and templates are obsolete, to consume the latest, force VS to download on startup .

  1. Ensure Azure Functions and Web Jobs Tools is the latest , right now it's 15.10.2046. On VS menus> Tools> Extensions and Updates> Updates, Update the extension if it's in the list.

  2. Remove %localappdata%\\AzureFunctionsTools and %userprofile%\\.templateengine folder.

  3. Reopen VS to create a new Function project, wait at the creation dialog, See Making sure all templates are up to date... .

    在此处输入图片说明 After a while, we can see the tip changes as

    在此处输入图片说明

  4. Click Refresh to work with the latest template instantly.

Don't forget to update Microsoft.NET.Sdk.Functions to latest(1.0.24 right now). And we don't need to install Microsoft.Azure.Webjobs separately which is referenced by Microsoft.NET.Sdk.Functions internally.

Once function starts we can see runtime Version=1.0.12205.0 right now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM