16

I have followed this tutorial to deploy a .NET Core console application to an Azure Web Service WebJob.

My app is running locally without any issue (with dotnet 1.0.0-preview2-003131) but when I try to run it from Azure console I have the following error :

Failed to load the dll from [D:\local\VirtualDirectory0\site\wwwroot\app_data\jobs\triggered\PopcornExportWebJob\hostpolicy.dll], HRESULT: 0x800700C1**

An error occurred while loading required library hostpolicy.dll from [D:\local\VirtualDirectory0\site\wwwroot\app_data\jobs\triggered\PopcornExportWebJob]

The version of Azure .Net is 1.0.0-rc4-004771 and the hostpolicy.dll file is the same than I use locally. In fact, when I download the zip of my deploy from Azure and when I run it locally, it is working fine. But it fails on Azure environment.

Also, here is my project.json:

{
      "publishOptions": {
        "include": [
          "run.cmd"
        ]
      },
      "buildOptions": {
        "emitEntryPoint": true,
        "copyToOutput": "appsettings.json"
      },
      "copyright": "bbougot",
      "dependencies": {
        "FubarCoder.RestSharp.Portable.Core": "4.0.7",
        "FubarCoder.RestSharp.Portable.HttpClient": "4.0.7",
        "Microsoft.ApplicationInsights.AspNetCore": "2.0.0",
        "Microsoft.Extensions.Configuration": "1.1.0",
        "Microsoft.Extensions.Configuration.Json": "1.1.0",
        "Microsoft.Extensions.DependencyInjection": "1.1.0",
        "Microsoft.Extensions.Logging": "1.1.0",
        "Microsoft.Extensions.Logging.Console": "1.1.0",
        "Microsoft.NETCore.App": "1.1.0",
        "MongoDB.Driver": "2.4.2",
        "StructureMap.Microsoft.DependencyInjection": "1.3.0"
      },
      "description": "Popcorn Api Exporter",
      "frameworks": {
        "netcoreapp1.1": {
          "imports": [
            "portable-net45+win8"
          ]
        }
      },
      "runtimes": {
        "win10-x64": {}
      },
      "scripts": {
        "postpublish": [ "7za.exe a -tzip PopcornExport.zip .\\bin\\Release\\PublishOutput\\*", 
                         ".\\WAWSDeploy.exe .\\PopcornExport.zip .\\popcornexport.PublishSettings /t app_data\\jobs\\triggered\\PopcornExportWebJob /v /d" ]
      },
      "title": "PopcornExport",
      "version": "1.0.0-*"
    }

I had to add the node runtimes (win10-x64 otherwise the app can't run locally). But, the Azure Web Service is running on Windows Server 2012. May it be an issue?

What did I miss?

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144

4 Answers4

20

Alright, I've figured it out.

If you want to deploy a dotnet core app to Azure Web Service, include the runtime "win7-x86" if you are running your app in 32-Bit platform mode.

For a Visual Studio 2015 solution, your project.json should include :

  "runtimes": {
    "win10-x64": {},
    "win7-x86": {} //IMPORTANT FOR AZURE DEPLOY
  },

Or if you have already migrated to Visual Studio 2017, your .csproj should include this in PropertyGroup:

<RuntimeIdentifiers>win10-x64;win7-x86</RuntimeIdentifiers>

Also, your publish profile should include the same thing:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <PublishProtocol>FileSystem</PublishProtocol>
    <Configuration>Release</Configuration>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <PublishDir>bin\Release\PublishOutput</PublishDir>
    <RuntimeIdentifier>win7-x86</RuntimeIdentifier> // IMPORTANT
  </PropertyGroup>
</Project>
  • Please help to mark it as an answer that will help more communities who have the similar issue. – Tom Sun - MSFT Feb 23 '17 at 02:34
  • 1
    Using VS2017, this solution worked - BUT I had to reverse the order of the runtime identifiers as it kept defaulting to the win10 config and when I changed it in the UI - until I changed the csproj to: `win7-x86;win10-x64` – Steve Land Jun 07 '17 at 11:34
  • This answer saved my bacon today... +1 Thank you! I find it odd that win10-x64 prevented proper communication with our DB. Why would windows 10 not be the officially supported Azure version? – Benj Sanders Aug 31 '17 at 20:28
  • Thank you so much, this saved my day! Other than @Steveland83 mentioned, the order of runtimeIdentifiers was not a problem for me. – phifi Sep 01 '17 at 16:15
11

I stopped seeing this error when I changed the contents of run.cmd from

dotnet MyWorker.dll

to

MyWorker.exe

x5657
  • 1,172
  • 2
  • 13
  • 26
3

This error could happen if the bitness of your application doesn't match the bitness of your App Service (e.g. publishing a 64-bit deployment to an App Service running in 32-bit mode).

To solve this I had to change the bitness to the correct setting in Azure:

enter image description here

To match the bitness of my publish profile in VS:

enter image description here

silkfire
  • 24,585
  • 15
  • 82
  • 105
0

All the other answers in this topic didn't help me. But then I noticed with dotnet --list-runtimes that I used a newer version of dotnet core on my pc (3.1.18) than was installed by default for the Azure App Service (3.1.16). Once I installed "ASP.NET Core 3.1 (x64) Runtime" with Version 3.1.18 as an Extension in the app service configuration, the problem went away. enter image description here

Urs Meili
  • 618
  • 7
  • 19