I had a working project with very dated NuGet package set for WebJob and storage. After a massive upgrade, I'm having three errors in this block only:
private static void Main()
{
var config = new JobHostConfiguration();
config.Queues.MaxDequeueCount = Convert.ToInt32(ConfigurationManager.AppSettings["MaxDequeueCount"]);
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["MaxPollingInterval"]));
config.Queues.BatchSize = Convert.ToInt32(ConfigurationManager.AppSettings["BatchSize"]); ;
config.NameResolver = new QueueNameResolver();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost();
host.RunAndBlock();
}
Errors:
Error CS0246: The type or namespace name 'JobHostConfiguration' could not be found (are you missing a using directive or an assembly reference?) \Program.cs:11
Error CS7036: There is no argument given that corresponds to the required formal parameter 'options' of 'JobHost.JobHost(IOptions<JobHostOptions>, IJobHostContextFactory)' \Program.cs:23
Error CS1061: 'JobHost' does not contain a definition for 'RunAndBlock' and no accessible extension method 'RunAndBlock' accepting a first argument of type 'JobHost' could be found (are you missing a using directive or an assembly reference?) \Program.cs:24
All the helps and questions are showing .Net Core code. I'm on .Net Framework 4.7.2. How do I go about setting up this code in old framework?
If you want to Azure WebJob SDK V3, the JobHostConfiguration
and JobHost
have been removed. In version V3, the host is an implementation of IHost
. For more details, please refer to here and here. Besides, please note that in version 3, you need to explicitly install the Storage binding extension required by the WebJobs SDK.
For example (Queue trigger in version 3)
#Install package Microsoft.Azure.WebJobs.Extensions.Storage 3.x
static async Task Main()
{
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage(a => {
a.BatchSize = 8;
a.NewBatchThreshold = 4;
a.MaxDequeueCount = 4;
a.MaxPollingInterval = TimeSpan.FromSeconds(15);
});
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}