Search code examples
c#azureasp.net-coreazure-webjobs

Azure Web Jobs fails to run once deployed


I've created a web job using web jobs 3.0 and dotnet core. This webjob is triggered by a service bus trigger, and currently works a treat locally. However, when I deploy the webjob to azure (via standard zip process, with type set to continuous, and scale to multi instance) the webjob deploys, and then fails to run with the following error.

[07/03/2019 11:30:47 cdae3f: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[07/03/2019 11:30:47 cdae3f: SYS INFO] Status changed to Running
[07/03/2019 11:30:48 cdae3f: INFO] 
[07/03/2019 11:30:48 cdae3f: INFO] D:\local\Temp\jobs\continuous\export-pdf\kucubmeb.3gj>dotnet exec Foo.ExportPdf.WebJob.dll 
[07/03/2019 11:30:48 cdae3f: ERR ] Error:
[07/03/2019 11:30:48 cdae3f: ERR ]   An assembly specified in the application ependencies manifest (Foo.ExportPdf.WebJob.deps.json) was not found:
[07/03/2019 11:30:48 cdae3f: ERR ]     package: 'System.Text.Encoding.CodePages', version: '4.5.1'
[07/03/2019 11:30:48 cdae3f: ERR ]     path: 'runtimes/win/lib/netcoreapp2.0/System.Text.Encoding.CodePages.dll'
[07/03/2019 11:30:48 cdae3f: ERR ] 
[07/03/2019 11:30:48 cdae3f: SYS ERR ] Job failed due to exit code -2147450740
[07/03/2019 11:30:48 cdae3f: SYS INFO] Process went down, waiting for 60 seconds
[07/03/2019 11:30:48 cdae3f: SYS INFO] Status changed to PendingRestart

Now looking at the error log above, it clearly suggests that "System.Text.Encoding.CodePages.dll" is missing, and thats whats causing the issue. So upon seeing this, I installed the nuget package for Encoding.CodePages, and can now see the .dll file in the output directory, however it's had no effect on the error message.

I have a feeling that either the error message is a red herring, or there's something up with the deps.json file which I don't understand.

Happy to provide any code examples too, but as this seems to be a deployment issue, wasn't sure it would be relevant.


Solution

  • I managed to get this working, whilst maybe not necessarily getting to the root of why the above doesn't work.

    I followed the article below, which outlines how to deploy dotnet core webjobs via a website and a publish profile. Publishing the webjob this way makes it start up and operate as expected.

    https://dotnetcoretutorials.com/2018/10/12/azure-webjobs-in-net-core-part-3

    In case the website is taken down, these are the basic steps I had to follow to get it working.

    1. Add an asp.net core website to your solution (blank template)
    2. Add the following snippet to your new websites csproj file (change the WebJobExample to be the name and location of your webjob)
        <Target Name="PostpublishScript" AfterTargets="Publish">
          <Exec Command="dotnet publish ..\WebJobExamples.WebJobExample\ -o 
          $(PublishDir)App_Data\Jobs\continuous\WebJobExample"   />
        </Target>
    
    1. Download publish profile from app service and deploy the application using Web Deploy (FTP did not work for me)