在部署.NET Core控制台应用程序到Azure WebJobs时出现加载hostpolicy.dll错误

16
我按照这个 tutorial 部署了一个 .NET Core 控制台应用程序到 Azure Web Service WebJob。
我的应用程序在本地运行没有问题(使用 dotnet 1.0.0-preview2-003131),但是当我尝试从 Azure 控制台运行它时,出现以下错误:

无法从 [D:\local\VirtualDirectory0\site\wwwroot\app_data\jobs\triggered\PopcornExportWebJob\hostpolicy.dll] 加载 dll,HRESULT: 0x800700C1**

[D:\local\VirtualDirectory0\site\wwwroot\app_data\jobs\triggered\PopcornExportWebJob] 加载所需库 hostpolicy.dll 时发生错误

Azure .Net 的版本是1.0.0-rc4-004771,hostpolicy.dll 文件与我本地使用的相同。事实上,当我从 Azure 下载部署包并在本地运行时,它可以正常工作。但是在 Azure 环境中失败了。

另外,这是我的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-*"
    }

我不得不添加节点runtimes(win10-x64,否则应用程序无法在本地运行)。但是,Azure Web Service正在运行Windows Server 2012。这可能是个问题吗?
我错过了什么?

类似问题:找不到库hostpolicy.dll - Michael Freidgeim
4个回答

20

好的,我已经弄清楚了。

如果你想将一个dotnet core 应用程序部署到Azure Web Service上,在32位平台模式下运行你的应用程序时,应该包含“win7-x86”运行时。

对于Visual Studio 2015解决方案,你的project.json应该包括:

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

或者如果您已经迁移到 Visual Studio 2017,您的 .csproj 文件应该包含以下内容:

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

此外,你的发布配置文件中也应包含相同的内容:

<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>

请帮忙将其标记为答案,这将有助于更多遇到类似问题的社区。 - Tom Sun - MSFT
1
使用VS2017,这个解决方案可以工作 - 但我不得不反转运行时标识的顺序,因为它一直默认为win10配置,当我在UI中更改它时 - 直到我将csproj更改为: <RuntimeIdentifiers>win7-x86;win10-x64</RuntimeIdentifiers> - Steve Land
这个答案今天救了我的命... +1 谢谢!我觉得很奇怪,win10-x64阻止了我们与数据库的正常通信。为什么Windows 10不是官方支持的Azure版本呢? - Benj Sanders
非常感谢,这救了我的一天!除了@Steveland83提到的之外,runtimeIdentifiers的顺序对我来说不是问题。 - phifi

11

当我将run.cmd文件中的内容从

dotnet MyWorker.dll

改为

MyWorker.exe

后,就不再出现这个错误了。


1
这也让我找到了解决方法,尽管它在我的web.config文件中:从: <aspNetCore processPath="dotnet" arguments=".\MyWorker.dll" ... />到: <aspNetCore processPath=".\MyWorker.exe" ... /> - Frank

3
这个错误可能是由于您的应用程序的位数与您的App Service的位数不匹配而导致的(例如,将64位部署发布到以32位模式运行的App Service)。
为了解决这个问题,我必须在Azure中更改正确的位数设置。

enter image description here

为了匹配我的 VS 发布配置文件的位数:

enter image description here


0

这个话题中的所有其他答案都没有帮助到我。但是我注意到使用 dotnet --list-runtimes,我在我的电脑上使用了一个比 Azure 应用服务默认安装的版本(3.1.16)更新的 dotnet core 版本(3.1.18)。一旦我在应用服务配置中安装了“ASP.NET Core 3.1 (x64) Runtime”作为扩展,并将其版本设置为 3.1.18,问题就解决了。 在此输入图像描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接