Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure WebJobs SDK and Emulator - Triggers not working

I'm attempting to update azure SDK from v1 to v3, and hook it up to the Azure Storage Emulator for testing; using console application and .NET Framework.

It doesn't appear to like any of the triggers that worked previously, the 'SomeFunction' in the error is a simple QueueTrigger with a timeout.

Exception: Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: 'Error indexing method '*.SomeFunction'

Inner Exception: InvalidOperationException: Storage account 'Storage' is not configured.

[Timeout("00:30:00")]
public static async Task SomeFunction([QueueTrigger("queue")] CloudQueueMessage message, CancellationToken cancellationToken)
{
    // do stuff
}

app.config:

<connectionStrings>
  <add name="AzureWebJobsDashboard" connectionString="AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;" />
  <add name="AzureWebJobsStorage" connectionString="AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;" />
</connectionStrings>
<appSettings>
  <add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
  <add key="AzureQueueName" value="queue" />
</appSettings>
like image 447
Chris Avatar asked Dec 14 '22 13:12

Chris


1 Answers

1. Use appSettings.json

Version 3 of Microsoft.Azure.WebJobs is no longer configured with an app.config file, but with an appSettings.json file. Place it in the root of your app and make sure the "Copy to output directory" property of the appSettings.json file is set to either Copy if newer or Copy always, or add this to your .csproj file directly using Always or PreserveNewest:

<Project ...> 
  ...
  <ItemGroup>
    <None Include="appSettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  ...
</Project>

2. appSettings.json content

Your appSettings.json file should have the Storage connection string:

in development

{
  "ConnectionStrings": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true"
  }
}

in production

{
  "ConnectionStrings": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=key;..."
  }
}

See this .NET Core 2.1 sample host application for more info on configuring in version 3. Though it might be somewhat different than .NET Framework that you are using.

like image 64
Artemious Avatar answered Dec 31 '22 06:12

Artemious