【问题标题】:Precompiled Azure Function Output to Blob Storage receiving 500 Internal Server Error预编译的 Azure 函数输出到 Blob 存储接收 500 内部服务器错误
【发布时间】:2019-06-09 16:47:51
【问题描述】:

我的 C# 预编译 Azure 函数的最终输出是以 JSON 文件的形式写入 Blob 存储。我写错了 Blob 存储吗?我在函数末尾的大括号上设置了断点,看起来它退出了函数。大约 20 秒后,我得到了异常:

执行函数时出现异常:ServiceBusTriggeredProcessAccepted。 Microsoft.Azure.WebJobs.Host:在函数返回后处理参数 outboundStringForBlobStorage 时出错:。 Microsoft.WindowsAzure.Storage:远程服务器返回错误:(500) 内部服务器错误。

Azure 函数是服务总线触发的事件。处理失败后,服务总线排队的项目会自动递增和重试,总共 10 次,然后才被移动到死信队列。应该注意的是对象的大小足够大,以至于常规队列对它们来说太小了。

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);
}

我正在使用: Azure Functions SDK NuGet 包 1.0.21
Microsoft.Azure.Webjobs 2.2.0
WindowsAzure.ServiceBus 5.0.0
DotNetFramework 4.6.1
Windows Azure 存储模拟器 5.8.0.0
运行时版本=1.0.11702.0

是否必须以某种方式对序列化进行清理?过去我不必进行消毒,但该对象中的数据已经改变,这就是问题开始发生的时候。我希望文件立即写入 blob 存储或立即返回异常,而不是在退出函数后 20 秒。

【问题讨论】:

    标签: c# azure azure-functions azure-servicebus-queues azure-blob-storage


    【解决方案1】:

    错误可能和序列化无关,我们重点关注这一行。

    Microsoft.WindowsAzure.Storage:远程服务器返回错误:(500) 内部服务器错误。

    如果我理解正确,blob 输入和输出都与 Azure 存储模拟器连接。 v5.8 Emulator failing blob writing 出了点问题。安装latest Emulator(现在是v5.9)可以解决这个问题。

    还要注意Runtime Version=1.0.11702.0 表示 CLI 和模板已过时,可以使用最新的 force VS to download on startup

    1. 确保 Azure Functions and Web Jobs Toolslatest,现在是 15.10.2046。在VS菜单>工具>扩展和更新>更新,如果它在列表中,更新扩展。

    2. 删除 %localappdata%\AzureFunctionsTools%userprofile%\.templateengine 文件夹。

    3. 重新打开VS新建一个Function项目,在创建对话框中等待,见Making sure all templates are up to date...

      一段时间后,我们可以看到提示变化为

    4. 单击“刷新”可立即使用最新模板。

    不要忘记将Microsoft.NET.Sdk.Functions 更新到最新版本(现在是 1.0.24)。并且我们不需要单独安装Microsoft.Azure.Webjobs,内部由Microsoft.NET.Sdk.Functions引用。

    一旦函数启动,我们现在可以看到运行时Version=1.0.12205.0

    【讨论】:

    • 更新 Azure 存储模拟器本身就可以解决问题。我的 Visual Studio 扩展没有任何扩展和更新。我不得不为 NuGet 包管理器运行命令行,因为 UI 没有显示任何更新。感谢您注意更新的版本。我只是假设我的 UI 工作正常。我没有你在 #2 中提到的任何文件夹或文件,所以如果你知道这是为什么会有所帮助。
    • @JustinNeff 尝试将 VS2017 更新到最新版本并再次尝试上述步骤。如果您已经使用最新版本(VS 和 Azure Functions 和 Web Jobs Tools),让我们使用PS script 下载新的 cli 和模板。
    • 我能够运行脚本。我从来没有看到“确保所有模板都是最新的......”我更新到 15.9.5 并且“扩展和更新”窗口报告错误 反序列化 Microsoft.VisualStudio.ExtensionManager 类型的对象时出错.VSGalleryExtensionQuery。遇到意外字符“
    • @JustinNeff 预计不会看到“确保所有模板都是最新的...”,因为我们已经使用脚本下载了 cli。之前没遇到过error deserializing ...,是不是对你的功能造成了问题?
    • 它没有。我似乎没有影响功能。我将在其他帖子中搜索解决方案。在 PS 脚本和修复之后,我现在有了 %localappdata%\AzureFunctionsTools 文件和 %userprofile%\.templateengine 感谢您的帮助。
    猜你喜欢
    • 2012-04-16
    • 2020-06-25
    • 2019-03-17
    • 1970-01-01
    • 2019-03-21
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    相关资源
    最近更新 更多