I'm new to Azure WebJobs. I'm attempting to make a certain method run daily at 11 PM:
The following is my code:
public class Functions
{
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
log.WriteLine(message);
}
public static void DailyReport([TimerTrigger("0 0 23 * * *")] TimerInfo timer, TextWriter log)
{
log.WriteLine("DailyReport was triggered!");
}
}
However, I keep getting an InvalidOperationException at startup:
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Microsoft Azure WebJobs SDK 'Dashboard' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:
1. Set the connection string named 'AzureWebJobsDashboard' in the connectionStrings section of the .config file in the following format <add name="AzureWebJobsDashboard" connectionString="DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY" />, or
2. Set the environment variable named 'AzureWebJobsDashboard', or
3. Set corresponding property of JobHostConfiguration.
Now, I've been wrestling with this for the better part of the day. Things I have tried:
- Configure
AzureWebJobsDashboard
andAzureWebJobsStorage
in the 'Application Settings' pane under 'Connection Strings'. Before, I had these in my App.config, but kept getting the error. This seems to have gotten me past the error on Azure: I now see a different exception in the Azure WebJobs log:
Unhandled Exception: Newtonsoft.Json.JsonException: Error creating 'Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueMessage+PersistentQueueMessageConverter'. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
I have no clue what to do about this either. However, while trying to run locally, I still get the InvalidOperationException complaining about the connection strings.
- Read somewhere that when testing locally, I should set an environment variable named
AzureWebJobsEnv
with valueDevelopment
. Did this, howeverconfig.IsDevelopment
still returns false. Not sure what that's about. - Created an Azure Web Jobs project from scratch and updated all the NuGet packages (this took two passes).
Verified that I have Azure Storage Emulator installed, and tried the emulator connection strings. My app.config now contains this:
<configuration> <appSettings> <add key="StorageConnectionString" value="UseDevelopmentStorage=true" /> </appSettings> <connectionStrings> <!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" --> <!-- For local execution, the value can be set either in this config file or through environment variables --> <add name="AzureWebJobsDashboard" connectionString="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;" /> <add name="AzureWebJobsStorage" connectionString="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;" /> </connectionStrings>
No luck: still crashes on startup with the same error.
This is my Program.cs:
static void Main()
{
var config = new JobHostConfiguration();
config.UseTimers();
config.Queues.MaxDequeueCount = 2;
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(4);
config.Queues.BatchSize = 2;
if (config.IsDevelopment) {
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
//host.Start();
}
Any help would be greatly appreciated!