【发布时间】:2019-02-17 19:19:39
【问题描述】:
我有一个带有服务总线触发器的 Azure 函数:
public static async Task Run([ServiceBusTrigger(
"%inputTopicName%",
"%subscriptionName%",
AccessRights.Manage,
Connection = "connection")]string mySbMsg)
在 99.9% 的调用中,触发器成功解析为 Azure 服务总线上的订阅。但有时,我会在日志中看到以下错误:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: UptimeChecker ---> System.ArgumentException: The argument connectionString is null or white space.
Parameter name: connectionString
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.FunctionInvocationFilterInvoker.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__16.MoveNext()
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__13.MoveNext()
服务总线触发器似乎无法从设置中解析connection 变量。
我试图在我的函数中添加一个调试过滤器,以了解发生了什么:
public class DebuggingFilter : FunctionInvocationFilterAttribute
{
public override Task OnExecutingAsync(FunctionExecutingContext executingContext, CancellationToken cancellationToken)
{
executingContext.Properties.Add("connection", ConfigurationManager.AppSettings["connection"]);
executingContext.Properties.Add("inputTopicName", ConfigurationManager.AppSettings["inputTopicName"]);
executingContext.Properties.Add("subscriptionName", ConfigurationManager.AppSettings["subscriptionName"]);
return base.OnExecutingAsync(executingContext, cancellationToken);
}
}
在我的函数中记录错误时,添加到FunctionExecutionContext 的属性会自动添加到日志消息中。这里奇怪的是,在 Azure Functions 抛出此异常的情况下,属性值被解析并显示在日志消息中。
这可能是什么原因?我在解决 Azure Functions 设置时遇到了多个问题,所以这可能是一个普遍问题?
【问题讨论】:
-
什么是 nuget 版本 * Microsoft.Azure.WebJobs.ServiceBus?你检查过 Kudu Logs YOURFUNCTION.scm.azurewebsites.net/DebugConsole D:\home\LogFiles\Application\Functions\function\YOURFUNCTION
-
该软件包的版本为 2.2.0。
-
您是否尝试更新到最新的 nuget?
-
你在本地测试吗?
-
本地这总是有效的。该问题仅出现在 Azure 上。
标签: c# azure-functions azureservicebus