azurewebjob

Azure WebJob Scaffolding failed


The WebJob is running on my local machine. After deployment to a App Service, the WebJob always has the status "Restart pending" with following logs attached.

[01/13/2020 16:04:03 > 8578d0: SYS INFO] Status changed to Starting
[01/13/2020 16:04:03 > 8578d0: SYS INFO] WebJob singleton setting is False
[01/13/2020 16:04:05 > 8578d0: SYS INFO] Run script 'dotnet-aspnet-codegenerator-design.exe' with script host - 'WindowsScriptHost'
[01/13/2020 16:04:05 > 8578d0: SYS INFO] Status changed to Running
[01/13/2020 16:04:06 > 8578d0: INFO] [Trace]: Command Line: 
[01/13/2020 16:04:06 > 8578d0: INFO] [Trace]:    at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
[01/13/2020 16:04:06 > 8578d0: INFO]    at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
[01/13/2020 16:04:06 > 8578d0: INFO]    at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass4_0.<<Execute>b__0>d.MoveNext()
[01/13/2020 16:04:06 > 8578d0: ERR ] Scaffolding failed.
[01/13/2020 16:04:06 > 8578d0: ERR ] Value cannot be null.
[01/13/2020 16:04:06 > 8578d0: ERR ] Parameter name: String
[01/13/2020 16:04:07 > 8578d0: SYS INFO] Status changed to Success
[01/13/2020 16:04:07 > 8578d0: SYS INFO] Process went down, waiting for 60 seconds
[01/13/2020 16:04:07 > 8578d0: SYS INFO] Status changed to PendingRestart

Since the scaffolding depends on a NuGet, here are the NuGet dependencies defined for the project

  <ItemGroup>
    <PackageReference Include="EntityFramework" Version="6.2.0" />
    <PackageReference Include="log4net" Version="2.0.8" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.4.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="System.IO.Compression" Version="4.3.0" />
    <PackageReference Include="System.Spatial" Version="5.8.4" />
    <PackageReference Include="Microsoft.Data.Edm" Version="5.8.4" />
    <PackageReference Include="Microsoft.Data.OData" Version="5.8.4" />
    <PackageReference Include="Microsoft.Data.Services.Client" Version="5.8.4" />
    <PackageReference Include="Microsoft.WindowsAzure.ConfigurationManager" Version="3.2.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="3.0.14" />
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.14" />
    <PackageReference Include="Microsoft.Azure.KeyVault.Core" Version="1.0.0" />
    <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>

and the project definition

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <GenerateSupportedRuntime>false</GenerateSupportedRuntime>  
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Platforms>AnyCPU;x64</Platforms>
    <RootNamespace>xxx.WebJob</RootNamespace>
  </PropertyGroup>

Had the same issue with the Azure.WebJobs 2.x, did upgrade to 3.x with no positive result. Main method of the WebJob

public static async Task Main()
{
    var hostBuilder = new HostBuilder()
        .ConfigureWebJobs(conf => conf.AddAzureStorage())
        // custom name resolver to pickup runtime information (dev/test/prod)
        .ConfigureServices(services => services.AddSingleton<INameResolver, AppSettingsResolver>())
        // set the config file to read azure configurations.
        .ConfigureAppConfiguration((context, builder) => builder.SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddEnvironmentVariables());

    using (var host = hostBuilder.Build())
        await host.RunAsync();
}

Solution

  • Seems to me that it's because you're supposed to be using .NET Core, but TargetFramework is Net Framework 4.7.2.

    Can you try to replace the following property group from:

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net472</TargetFramework>
        <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
        <GenerateSupportedRuntime>false</GenerateSupportedRuntime>  
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
        <Platforms>AnyCPU;x64</Platforms>
        <RootNamespace>xxx.WebJob</RootNamespace>
      </PropertyGroup>
    

    to

      <PropertyGroup>
        <TargetFramework>netcoreapp2.2</TargetFramework>
        <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
      </PropertyGroup>