![](/img/trans.png)
[英]Value cannot be null. Parameter name: source
[英]Azure function: Value cannot be null. Parameter name: source
最近,当我调用我的 Azure 函数时,每当我尝试向 AddGroup 函数发出 HTTP 请求时,都会看到此异常。
有任何想法吗?
Time 11:04:02 AM
Exception type Microsoft.Azure.WebJobs.Host.FunctionInvocationException
Exception message Exception while executing function: AddGroup <--- Value cannot be null. Parameter name: source
Host.Results
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: AddGroup ---> System.ArgumentNullException: Value cannot be null.
Parameter name: source
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.FunctionInvocationFilterInvoker.<InvokeAsync>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.<InvokeAsync>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.<ExecuteWithWatchersAsync>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.<ExecuteWithLoggingAsync>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.<ExecuteWithLoggingAsync>d__16.MoveNext()
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>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.<TryExecuteAsync>d__13.MoveNext()
我想通了 - 我有一个 NuGet 包冲突。 我的一个项目试图引用版本 Newtonsoft Json 9.0.1(Azure Functions SDK 所依赖的版本)以及另一个项目想要的 11.0.2。 我最终让另一个项目也使用了 9.0.1 版本的包。
我遇到了同样的问题,对我来说,错误的文本实际上有点相关。 我们从 Azure 得到的错误的奇怪部分是函数应用部署在一个订阅上运行良好,但在另一个订阅下给了我们这个“值不能为空”错误。 我无法谈论订阅之间的差异,但我可以解释我们是如何解决问题的。
我们有一个 Azure Function App 执行的async Task
方法。 在这个方法中,我们调用了一个 awaitable 方法,它返回一个IEnumerable<Thing>
类型的Task
,其中Thing
是一个简单的数据模型类。 被调用的代码如下所示:
var things = await SomeFactory.LoadXmlRequest<Thing>(xml, auth);
紧接着,我们需要检查things
包含任何数据,因此我们进行了如下检查:
if (things.Any()) { ... }
我团队中一位勇敢的开发人员建议我们先检查things
为空,然后再检查它是否包含任何数据。 我们将调用修改为如下所示:
if (things != null && things.Any()) { ... }
这行得通。 我们所要做的就是在调用.Any()
LINQ 扩展方法之前检查该对象是否为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.