使用 .NET Core 2 的 Azure WebJobs 失败 "Invalid storage account"
Azure WebJobs using .NET Core 2 failing with "Invalid storage account"
按照 Matt Roberts 出色的分步文章 Azure WebJobs in .NET Core 2 (with DI and configuration) 我创建了一个部署没有问题的解决方案(使用 Visual Studio 2017),但失败并出现 "Invalid storage account" 异常:
Unhandled Exception: System.InvalidOperationException: Invalid storage account 'mywebjobsstorage'. Please make sure your credentials are correct. ---> System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties> Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetServicePropertiesAsync(System.Threading.CancellationToken)'.
我可以看到必须选择 AzureWebJobsDashboard 和 AzureWebJobsStorage 环境变量,因为错误明确命名了连接字符串中使用的 AccountName。
我尝试了存储连接字符串的两种变体,结果相同:
DefaultEndpointsProtocol=https;AccountName=mywebjobsstorage;AccountKey=********
DefaultEndpointsProtocol=https;AccountName=mywebjobsstorage;AccountKey=********;EndpointSuffix=core.windows.net
知道问题出在哪里吗?
这是完整的异常日志,以防它包含任何其他线索,或者我被误导了:
[03/29/2018 07:52:43 > d801c3: SYS INFO] Status changed to Initializing
[03/29/2018 07:52:48 > d801c3: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[03/29/2018 07:52:48 > d801c3: SYS INFO] Status changed to Running
[03/29/2018 07:52:48 > d801c3: INFO]
[03/29/2018 07:52:48 > d801c3: INFO] D:\local\Temp\jobs\triggered\MyWebJobs\uoyrr1m3.5sq>dotnet MyWebJobs.dll
[03/29/2018 07:52:50 > d801c3: ERR ]
[03/29/2018 07:52:50 > d801c3: ERR ] Unhandled Exception: System.InvalidOperationException: Invalid storage account 'mywebjobsstorage'. Please make sure your credentials are correct. ---> System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties> Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetServicePropertiesAsync(System.Threading.CancellationToken)'.
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Storage.Blob.StorageBlobClient.GetServicePropertiesAsync(CancellationToken cancellationToken)
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageCredentialsValidator.<ValidateCredentialsAsyncCore>d__1.MoveNext()
[03/29/2018 07:52:50 > d801c3: ERR ] --- End of inner exception stack trace ---
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageCredentialsValidator.<ValidateCredentialsAsyncCore>d__1.MoveNext()
[03/29/2018 07:52:50 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageCredentialsValidator.<ValidateCredentialsAsync>d__0.MoveNext()
[03/29/2018 07:52:50 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.<CreateAndValidateAccountAsync>d__24.MoveNext()
[03/29/2018 07:52:50 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.<TryGetAccountAsync>d__25.MoveNext()
[03/29/2018 07:52:51 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.JobHostConfigurationExtensions.<CreateJobHostContextAsync>d__1.MoveNext()
[03/29/2018 07:52:51 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.JobHost.<InitializeHostAsync>d__44.MoveNext()
[03/29/2018 07:52:51 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.JobHost.<StartAsyncCore>d__25.MoveNext()
[03/29/2018 07:52:51 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.JobHost.Start()
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.JobHost.RunAndBlock()
[03/29/2018 07:52:51 > d801c3: ERR ] at MyWebJobs.Program.Main(String[] args) in C:\!Projects\SomeProject\src\MyWebJobs\Program.cs:line 30
[03/29/2018 07:52:51 > d801c3: SYS INFO] Status changed to Failed
[03/29/2018 07:52:51 > d801c3: SYS ERR ] Job failed due to exit code -532462766
看起来这些 NuGet 包中有一个错误:
- Microsoft.Azure.WebJobs
- Microsoft.Azure.WebJobs.扩展
我使用的是这些软件包的 v2.2.0,但它们似乎有一个错误。在没有任何代码更改的情况下将这些交换为 v3 beta pre-releases 的 NuGet 包解决了这个问题。
更新
.NET Core 仅支持 v3+ - https://github.com/Azure/azure-webjobs-sdk/issues/1649#issuecomment-377633805
我们最近遇到了与我们的一项网络作业类似的问题,该作业早些时候运行良好但突然停止工作。 Web 作业尝试每分钟重新启动一次,但失败并显示错误消息 无效存储帐户 ABStorage。请确保您的凭据正确无误。 Web 作业仍处于 Pending Restart 状态。经过调查,我们发现存储连接字符串完全正常,而 Azure 存储 SDK 中存在一些错误,导致在 Azure 门户上针对存储帐户配置的 CORS 规则未被正确解释。在 Azure 门户中,我们在 Azure 存储上只有 1 个 CORS 规则,并选择了所有允许的 HTTP 方法。
我们更新了存储帐户上的 CORS 规则,使每个域具有一个 HTTP 方法,并且 Web 作业能够立即启动。
按照 Matt Roberts 出色的分步文章 Azure WebJobs in .NET Core 2 (with DI and configuration) 我创建了一个部署没有问题的解决方案(使用 Visual Studio 2017),但失败并出现 "Invalid storage account" 异常:
Unhandled Exception: System.InvalidOperationException: Invalid storage account 'mywebjobsstorage'. Please make sure your credentials are correct. ---> System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties> Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetServicePropertiesAsync(System.Threading.CancellationToken)'.
我可以看到必须选择 AzureWebJobsDashboard 和 AzureWebJobsStorage 环境变量,因为错误明确命名了连接字符串中使用的 AccountName。
我尝试了存储连接字符串的两种变体,结果相同:
DefaultEndpointsProtocol=https;AccountName=mywebjobsstorage;AccountKey=********
DefaultEndpointsProtocol=https;AccountName=mywebjobsstorage;AccountKey=********;EndpointSuffix=core.windows.net
知道问题出在哪里吗?
这是完整的异常日志,以防它包含任何其他线索,或者我被误导了:
[03/29/2018 07:52:43 > d801c3: SYS INFO] Status changed to Initializing
[03/29/2018 07:52:48 > d801c3: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[03/29/2018 07:52:48 > d801c3: SYS INFO] Status changed to Running
[03/29/2018 07:52:48 > d801c3: INFO]
[03/29/2018 07:52:48 > d801c3: INFO] D:\local\Temp\jobs\triggered\MyWebJobs\uoyrr1m3.5sq>dotnet MyWebJobs.dll
[03/29/2018 07:52:50 > d801c3: ERR ]
[03/29/2018 07:52:50 > d801c3: ERR ] Unhandled Exception: System.InvalidOperationException: Invalid storage account 'mywebjobsstorage'. Please make sure your credentials are correct. ---> System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties> Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetServicePropertiesAsync(System.Threading.CancellationToken)'.
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Storage.Blob.StorageBlobClient.GetServicePropertiesAsync(CancellationToken cancellationToken)
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageCredentialsValidator.<ValidateCredentialsAsyncCore>d__1.MoveNext()
[03/29/2018 07:52:50 > d801c3: ERR ] --- End of inner exception stack trace ---
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageCredentialsValidator.<ValidateCredentialsAsyncCore>d__1.MoveNext()
[03/29/2018 07:52:50 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageCredentialsValidator.<ValidateCredentialsAsync>d__0.MoveNext()
[03/29/2018 07:52:50 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:50 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:50 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.<CreateAndValidateAccountAsync>d__24.MoveNext()
[03/29/2018 07:52:50 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.DefaultStorageAccountProvider.<TryGetAccountAsync>d__25.MoveNext()
[03/29/2018 07:52:51 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.Host.Executors.JobHostConfigurationExtensions.<CreateJobHostContextAsync>d__1.MoveNext()
[03/29/2018 07:52:51 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.JobHost.<InitializeHostAsync>d__44.MoveNext()
[03/29/2018 07:52:51 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.JobHost.<StartAsyncCore>d__25.MoveNext()
[03/29/2018 07:52:51 > d801c3: ERR ] --- End of stack trace from previous location where exception was thrown ---
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.JobHost.Start()
[03/29/2018 07:52:51 > d801c3: ERR ] at Microsoft.Azure.WebJobs.JobHost.RunAndBlock()
[03/29/2018 07:52:51 > d801c3: ERR ] at MyWebJobs.Program.Main(String[] args) in C:\!Projects\SomeProject\src\MyWebJobs\Program.cs:line 30
[03/29/2018 07:52:51 > d801c3: SYS INFO] Status changed to Failed
[03/29/2018 07:52:51 > d801c3: SYS ERR ] Job failed due to exit code -532462766
看起来这些 NuGet 包中有一个错误:
- Microsoft.Azure.WebJobs
- Microsoft.Azure.WebJobs.扩展
我使用的是这些软件包的 v2.2.0,但它们似乎有一个错误。在没有任何代码更改的情况下将这些交换为 v3 beta pre-releases 的 NuGet 包解决了这个问题。
更新
.NET Core 仅支持 v3+ - https://github.com/Azure/azure-webjobs-sdk/issues/1649#issuecomment-377633805
我们最近遇到了与我们的一项网络作业类似的问题,该作业早些时候运行良好但突然停止工作。 Web 作业尝试每分钟重新启动一次,但失败并显示错误消息 无效存储帐户 ABStorage。请确保您的凭据正确无误。 Web 作业仍处于 Pending Restart 状态。经过调查,我们发现存储连接字符串完全正常,而 Azure 存储 SDK 中存在一些错误,导致在 Azure 门户上针对存储帐户配置的 CORS 规则未被正确解释。在 Azure 门户中,我们在 Azure 存储上只有 1 个 CORS 规则,并选择了所有允许的 HTTP 方法。