2

I've trouble with running my isolated .NET 5 Azure Function on my local computer and Visual Studio 2022. I've next message:

Visual Studio error message

Microsoft Visual Studio Debug Console

Failed to load the dll from [C:\Users\***\AppData\Local\AzureFunctionsTools\Releases\3.30.1\cli_x64\hostpolicy.dll], HRESULT: 0x800700C1

An error occurred while loading required library hostpolicy.dll from [C:\Users\***\AppData\Local\AzureFunctionsTools\Releases\3.30.1\cli_x64]

C:\Program Files (x86)\dotnet\dotnet.exe (process 15628) exited with code -2147450750.

Press any key to close this window . . .

Here is the code of the project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <!-- Some code here -->
  </ItemGroup>
  <ItemGroup>
    <!-- Some code here -->
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

I've tried these things:

  1. Adding <RuntimeIdentifiers>win10-x64;win7-x86</RuntimeIdentifiers> to the PropertyGroup tag of the project file _(like on this question Error loading hostpolicy.dll while deploying .NET Core console app to Azure WebJobs) → Didn't work
  2. Setting the path environment variable C:\Program Files\dotnet\ above C:\Program Files (x86)\dotnet\ (like on this article .NET 6 Azure Functions Isolated: An error occurred while loading required library hostpolicy.dll) → Didn't work
  3. Droped and recreated the project → Didn't work
  4. Switching to Visual Studio 2019 → Working

Why doesn't it work with Visual Studio 2022?

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
  • 1
    I'm troubleshooting the same problem with my project right now. Curious, have you installed Visual Studio 2022? I have and I'm wondering if that is causing the problem. – Chad Green Nov 18 '21 at 14:39
  • @ChadGreen: Yes I'm using Visual Studio 2022 preview – H. Pauwelyn Nov 18 '21 at 15:16
  • @ChadGreen: I've updated my question. It's only 2022. Using 2019 it's working. – H. Pauwelyn Nov 18 '21 at 15:34
  • That's ERROR_BAD_EXE_FORMAT. You're running the 32-bit version of dotnet.exe (note how it got loaded from c:\program files (x86)) but try to load a 64-bit DLL. Not good, run c:\program files\dotnet\dotnet.exe instead. – Hans Passant Nov 18 '21 at 19:14

1 Answers1

1

Hans Passant spotted the right answer: the 32-bit version of dotnet.exe is trying to load a 64-bit DLL. Look at your path and remove the x86 path to 32-bit dotnet.exe. Restart Visual Studio 2022 and it should work properly.

Llew
  • 11
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33990219) – Brisbe Mar 13 '23 at 14:44