Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
739 views
in Technique[技术] by (71.8m points)

c# - Error loading hostpolicy.dll while deploying .NET Core console app to Azure WebJobs

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:localVirtualDirectory0sitewwwrootapp_datajobsriggeredPopcornExportWebJobhostpolicy.dll], HRESULT: 0x800700C1

An error occurred while loading required library hostpolicy.dll from [D:localVirtualDirectory0sitewwwrootapp_datajobsriggeredPopcornExportWebJob]

The version of Azure dotnet 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>binReleasePublishOutput</PublishDir>
    <RuntimeIdentifier>win7-x86</RuntimeIdentifier> // IMPORTANT
  </PropertyGroup>
</Project>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...