[英]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.我已按照本教程将 .NET Core 控制台应用程序部署到 Azure Web 服务 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 :我的应用程序在本地运行没有任何问题(使用 dotnet 1.0.0-preview2-003131 )但是当我尝试从 Azure 控制台运行它时出现以下错误:
Failed to load the dll from [D:\\local\\VirtualDirectory0\\site\\wwwroot\\app_data\\jobs\\triggered\\PopcornExportWebJob\\hostpolicy.dll], HRESULT: 0x800700C1无法从 [D:\\local\\VirtualDirectory0\\site\\wwwroot\\app_data\\jobs\\triggered\\PopcornExportWebJob\\hostpolicy.dll] 加载 dll,HRESULT:0x800700C1
An error occurred while loading required library hostpolicy.dll from [D:\\local\\VirtualDirectory0\\site\\wwwroot\\app_data\\jobs\\triggered\\PopcornExportWebJob]从 [D:\\local\\VirtualDirectory0\\site\\wwwroot\\app_data\\jobs\\triggered\\PopcornExportWebJob] 加载所需的库 hostpolicy.dll 时发生错误
The version of Azure dotnet is 1.0.0-rc4-004771 and the hostpolicy.dll file is the same than I use locally. Azure dotnet的版本是1.0.0-rc4-004771 ,hostpolicy.dll文件和我本地用的一样。 In fact, when I download the zip of my deploy from Azure and when I run it locally, it is working fine.事实上,当我从 Azure 下载部署的 zip 文件并在本地运行时,它运行良好。 But it fails on Azure environment.但它在 Azure 环境中失败。
Also, here is my project.json:另外,这是我的 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).我必须添加节点运行时(win10-x64,否则应用程序无法在本地运行)。 But, the Azure Web Service is running on Windows Server 2012. May it be an issue?但是,Azure Web 服务运行在 Windows Server 2012 上。这可能是个问题吗?
What did I miss?我错过了什么?
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.如果要将 dotnet 核心应用程序部署到 Azure Web 服务,并且在 32 位平台模式下运行应用程序,请包含运行时“ win7-x86 ”。
For a Visual Studio 2015 solution, your project.json should include :对于 Visual Studio 2015 解决方案,您的 project.json 应包括:
"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:或者,如果您已经迁移到 Visual Studio 2017,则您的 .csproj 应将其包含在 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>
I stopped seeing this error when I changed the contents of run.cmd from当我将 run.cmd 的内容从
dotnet MyWorker.dll
to到
MyWorker.exe
This error could happen if the bitness of your application doesn't match the bitness of your App Service (eg publishing a 64-bit deployment to an App Service running in 32-bit mode).如果应用程序的位数与应用服务的位数不匹配(例如,将 64 位部署发布到以 32 位模式运行的应用服务),则可能会发生此错误。
To solve this I had to change the bitness to the correct setting in Azure:为了解决这个问题,我必须在 Azure 中将位数更改为正确的设置:
To match the bitness of my publish profile in VS:为了匹配我在 VS 中发布配置文件的位数:
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).但是后来我注意到dotnet --list-runtimes
我在我的电脑 (3.1.18) 上使用了比 Azure 应用服务 (3.1.16) 默认安装的新版本的 dotnet 核心。 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.一旦我安装了“ASP.NET Core 3.1 (x64) Runtime”和版本 3.1.18 作为应用服务配置中的扩展,问题就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.