简体   繁体   中英

Azure function: Value cannot be null. Parameter name: source

Lately, when I call my Azure function, I see this exception come up whenever I try to make a HTTP request to the AddGroup function.

  • It used to work until I updated some NuGet packages (specifically, Newtonsoft JSON 11.0.2)
  • It works fine when I run the function locally- it's something to do with Azure
  • I've pushed new code and restarted the function many times
  • Other questions here say it might be a connection string problem, but, again, it works on my local machine and I haven't touched the connection strings
  • When I try to attach the cloud debugger, the exception shows up before it hits any break points in my code.

Any ideas?

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()

I figured it out- I had a NuGet package conflict. One of my projects was trying to reference version Newtonsoft Json 9.0.1 (which the Azure Functions SDK depends on) and also 11.0.2, which another project wanted. I wound up having the other project also use the 9.0.1 version of the package.

I came across this same problem, and for me the text of the error was actually somewhat relevant. The odd part about the error we were getting from Azure is that the function app deployment worked fine on one subscription, but gave us this "Value cannot be null" error under another subscription. I can't speak to the differences between subscriptions, but I can explain how we resolved the problem.

We have an async Task method that our Azure Function App executes. In this method, we call an awaitable method that returns a Task of type IEnumerable<Thing> , where Thing is a simple data model class. The code getting called looks something like this:

var things = await SomeFactory.LoadXmlRequest<Thing>(xml, auth);

Immediately thereafter we needed to check to see if things contained any data, so we had a check that looks something like this:

if (things.Any()) { ... }

An intrepid developer on my team suggested we first check if things was null prior to checking if it contained any data. We modified the call to look something like this instead:

if (things != null && things.Any()) { ... }

This worked. All we had to do was check to see if this object was null before calling the .Any() LINQ extension method on it.

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