Skip to content

System.ArgumentNullException running new Function project from Visual Studio #1409

@alexb5dh

Description

@alexb5dh

Created fresh Azure Functions project from VS 2019 with storage in Azure. Trying to start it gives the following error: System.ArgumentNullException: 'Value cannot be null. Parameter name: path' at

System.IO.FileSystem.dll!System.IO.File.ReadAllText(string path)	Unknown
System.IO.Abstractions.dll!System.IO.Abstractions.FileWrapper.ReadAllText(string path)	Unknown
func.dll!Azure.Functions.Cli.Common.FileSystemHelpers.ReadAllTextFromFile(string path) Line 33	C#
func.dll!Azure.Functions.Cli.Common.AppSettingsFile.AppSettingsFile(string filePath) Line 18	C#
[Lightweight Function]	
Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.Serialization.ObjectConstructor<object> creator, string id)	Unknown
Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, string id, out bool createdFromNonDefaultCreator)	Unknown
Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, object existingValue)	Unknown
Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, object existingValue)	Unknown
Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(Newtonsoft.Json.JsonReader reader, System.Type objectType, bool checkAdditionalContent)	Unknown
Newtonsoft.Json.dll!Newtonsoft.Json.JsonSerializer.DeserializeInternal(Newtonsoft.Json.JsonReader reader, System.Type objectType)	Unknown
Newtonsoft.Json.dll!Newtonsoft.Json.JsonConvert.DeserializeObject(string value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings)	Unknown
Newtonsoft.Json.dll!Newtonsoft.Json.JsonConvert.DeserializeObject<Azure.Functions.Cli.Common.AppSettingsFile>(string value, Newtonsoft.Json.JsonSerializerSettings settings)	Unknown
func.dll!Azure.Functions.Cli.Common.AppSettingsFile.AppSettingsFile(string filePath) Line 18	C#
func.dll!Azure.Functions.Cli.Common.SecretsManager.GetSecrets() Line 42	C#
func.dll!Azure.Functions.Cli.Helpers.WorkerRuntimeLanguageHelper.GetCurrentWorkerRuntimeLanguage(Azure.Functions.Cli.Interfaces.ISecretsManager secretsManager) Line 134	C#
func.dll!Azure.Functions.Cli.Helpers.GlobalCoreToolsSettings.Init(Azure.Functions.Cli.Interfaces.ISecretsManager secretsManager, string[] args) Line 48	C#
func.dll!Azure.Functions.Cli.ConsoleApp.ConsoleApp(string[] args, System.Reflection.Assembly assembly, Autofac.IContainer container) Line 173	C#
func.dll!Azure.Functions.Cli.ConsoleApp.RunAsync<Azure.Functions.Cli.Program>(string[] args, Autofac.IContainer container) Line 38	C#
func.dll!Azure.Functions.Cli.ConsoleApp.Run.AnonymousMethod__0() Line 32	C#
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.Task>.InnerInvoke()	Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task..cctor.AnonymousMethod__278_1(object obj)	Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot)	Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteEntryUnsafe()	Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()	Unknown
System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()	Unknown
System.Private.CoreLib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()	Unknown

Checking the source code I see that problem is as following:

  • AppSettingsFile constructor tries to deserialize another instance of AppSettingsFile via Json.NET.
  • Since it doesn't have any other constuctors, one with string filePath is used with null as parameter value.
  • null passed gives error above during recursive deserialization attempt.

It seems that adding empty private constructor to AppSettingsFile should solve this, or there's something wrong with my installation.

CLI v2.24.0
VS 2019 v16.2.0 Preview 3.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions