简体   繁体   English

Azure .net6.0 上的函数无法在本地运行 hostpolicy.dll 错误

[英]Azure Functions on .net6.0 fail to run locally with hostpolicy.dll error

One of our developers is currently building an Azure Function app in.Net 6.0 using Visual Studio 2022 Preview on Windows 10.我们的一位开发人员目前正在 Windows 10 上使用 Visual Studio 2022 Preview 在.Net 6.0 中构建 Azure Function 应用程序。

The solution has several projects, 1 Azure Function and several class libraries.该解决方案有几个项目,1 Azure Function 和几个 class 库。 It fails to run with:它无法运行:

Metadata generation failed.元数据生成失败。 Exit code: '-2147450750' Error: 'Failed to load the dll from [C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0\hostpolicy.dll], HRESULT: 0x800700C1An error occurred while loading required library hostpolicy.dll from [C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0]' DATA.Services.CompaniesQuery.Function C:\Users\r_ver.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\4.0.1\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets 37退出代码:'-2147450750' 错误:'无法从 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0\hostpolicy.dll] 加载 dll,HRESULT:0x800700C1加载时发生错误需要library hostpolicy.dll from [C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0]' DATA.Services.CompaniesQuery.Function C:\Users\r_ver.nuget\packages\microsoft.azure.webjobs .script.extensionsmetadatagenerator\4.0.1\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets 37

Microsoft.NETCore.App is using version 6.0.1 and is listed until Solution Explorer in the Azure Function project in Dependencies > Frameworks > Microsoft.NETCore.App. Microsoft.NETCore.App 正在使用版本 6.0.1,并且在依赖项 > 框架 > Microsoft.NETCore.App 中的 Azure Function 项目中的解决方案资源管理器中列出。

We have tried the following:我们尝试了以下方法:

Reinstalling.Net 6 SDK重装.Net 6 SDK

Reinstalled VS 2022 version 17.0.5重新安装 VS 2022 版本 17.0.5

Laptop restart笔记本电脑重启

Deleted contents of "C:\Users\someuser.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator" folder.删除了“C:\Users\someuser.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator”文件夹的内容。

C:\Program Files\dotnet\shared\Microsoft.NETCore.App has folder for.Net Core 2.0.0 and 6.0.1 C:\Program Files\dotnet\shared\Microsoft.NETCore.App 有 .Net Core 2.0.0 和 6.0.1 的文件夹

The error relates to 2.0.0 however no references are made to this in the project including csproj files.该错误与 2.0.0 有关,但是在包括 csproj 文件的项目中没有对此进行引用。

Is a manual update required to the targets file?目标文件是否需要手动更新? Currently not aware of any resolution to this.目前不知道有任何解决方案。

I have tried in my environment and it works as expected,我已经在我的环境中尝试过,它按预期工作,

To build an Azure Function app in .Net 6.0 using Visual Studio 2022 Preview(17.0.5) on Windows 10.在 Windows 10 上使用Visual Studio 2022 Preview(17.0.5) 在.Net 6.0中构建 Azure Function 应用程序。

Below are the steps which i have followed:以下是我遵循的步骤:

After that make sure that we have Azure function runtime v4 is available in .csproj file as below:之后确保我们有 Azure function 运行时 v4 在.csproj文件中可用,如下所示:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

在此处输入图像描述

  • Allowed firewall setting允许的防火墙设置

在此处输入图像描述

OUTPUT:- OUTPUT:-

在此处输入图像描述 在此处输入图像描述

NOTE:-笔记:-

  • When installing Azure function core tools version, make sure that we have installed only one core tool version on our computer.在安装 Azure function 核心工具版本时,请确保我们的计算机上只安装了一个核心工具版本。

  • .net 6 supports Azure function runtime version 4x only. .net 6 仅支持 Azure function 运行时版本 4x。

For more information please refer this Microsoft Documentation : Azure Functions runtime versions overview有关详细信息,请参阅此Microsoft 文档Azure 函数运行时版本概述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM