Hi @EnenDaveyBoy ,
Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
Root Cause
The error "The library 'hostpolicy.dll' ... was not found" indicates that the .NET runtime cannot find the necessary components to start the application. In the context of Azure Functions (Isolated Worker), this typically happens when:
- The Main Project is missing the SDK: You mentioned moving all package references to another project. The Main Project (the executable) must retain the reference to
Microsoft.Azure.Functions.Worker.Sdk. This package is responsible for the build process that generates the requiredfunctions.metadata,deps.json, andruntimeconfig.jsonfiles. Without it, the project is just a standard Console App that doesn't know how to run as a Function App. - Incorrect Output Type: The Main Project must have
<OutputType>Exe</OutputType>, while the Referenced Project (Library) must be<OutputType>Library</OutputType>.
Solution: Correct Project Structure
To fix this, you need to split the references correctly between your Main Project (the startup app) and your Class Library (where your Durable Functions logic lives).
- Main Function App Project (
.csproj)
This project runs the application. It must be an Executable and contain the build SDK.- OutputType:
Exe - Required Package:
Microsoft.Azure.Functions.Worker.Sdk - Reference: Must reference your Class Library.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <OutputType>Exe</OutputType> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" /> <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\MyDurableFunctionsLibrary\MyDurableFunctionsLibrary.csproj" /> </ItemGroup> </Project>
- OutputType:
- Class Library Project (
.csproj):
This project contains your Orchestrators, Activities, and Entities.- OutputType:
Library - Required Packages:
Microsoft.Azure.Functions.Worker,Microsoft.Azure.Functions.Worker.Extensions.DurableTask - NO SDK: Do not include
Microsoft.Azure.Functions.Worker.Sdkhere (or if you do, ensure it doesn't conflict with the main app's build, but it is generally not needed for the library code itself).<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <OutputType>Library</OutputType> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" /> </ItemGroup> </Project>
- OutputType:
- Program.cs (In Main Project) :
Ensure yourProgram.csis in the Main Project and correctly sets up the host. The dependencies from the referenced library will be loaded automatically if the project reference is correct.using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .ConfigureServices(services => { // Register any services defined in your Class Library here }) .Build(); host.Run();