I am attempting to retrieve config values with a static class:
public static class Configurator
{
public static string HashesConnectionString { get; } = Environment.GetEnvironmentVariable("HashesConnectionString");
public static string SftpUser { get; } = Environment.GetEnvironmentVariable("SftpUser");}
When attempting to retrieve these from a separate class, I am getting a very embarrassing error:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'MyHandler.Configuration.Configurator' threw an exception.
Source=MyHandler
StackTrace:
at MyHandler.Configuration.Configurator.get_HashesConnectionString() in C:\Users\John.S\source\repos\MyHandler\MyHandler\Configuration\Configurator.cs:line 11
at MyHandler.OnMumboCaseBlobTriggered.RunAsync(CloudBlockBlob blob, String name, TraceWriter log) in C:\Users\John.S\source\repos\MyHandler\MyHandler\Functions\OnMumboCaseBlobTriggered.cs:line 31
at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.<InvokeAsync>d__9.MoveNext()
Inner Exception 1:
ArgumentNullException: Value cannot be null.
Parameter name: String
Initially I thought something funny was happening with Environment.GetEnvironmentVariable()
but this did not turn out to be the case, when I tested this hypothesis by hardcoding the config values like so:
public static class Configurator
{
public static string HashesConnectionString {get;} = "my hardcoded value"
}
But the exception persists!
What is wrong with my static class? Am I improperly using this class?
This exception occurs in this example:
public static void RunAsync([BlobTrigger("awesomeBlobber", Connection = "StorageConnectionString")] CloudBlockBlob blob, string name, TraceWriter log)
{
var connString = Configuration.Configurator.HashesConnectionString;
}
User contributions licensed under CC BY-SA 3.0