Azure Durable Function Doesn't allow me to move its references into another Project C#

EnenDaveyBoy 71 Reputation points
2025-11-20T21:22:01.9+00:00

Hi

I am building a project using Azure Functions and I want to refactor the apps and more all the Package References into another project so:

<ItemGroup>
   <FrameworkReference Include="Microsoft.AspNetCore.App" />
     <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.50.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.50.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.11.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.6" />
  </ItemGroup>

Would be in another project and then that project would be referenced into the main project, but this causes an error of:

 Language Worker Process exited. Pid=5480.
[2025-11-20T21:14:07.983Z] C:\Program Files\dotnet\dotnet.exe exited with code -2147450749 (0x80008083). A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'D:\src\Entity.Text.Field\src\FunctionApps\CommandHandlers\AZSTCommandFn\src\bin\Debug\net8.0\'.,Failed to run as a self-contained app.
[2025-11-20T21:14:07.993Z] Exceeded language worker restart retry count for runtime:dotnet-isolated. Shutting down and proactively recycling the Functions Host to recover
[2025-11-20T21:15:07.943Z] Starting worker process failed
[2025-11-20T21:15:07.944Z] Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out.
[2025-11-20T21:15:07.948Z] Failed to start language worker process for runtime: dotnet-isolated. workerId:04402a8c-c0d9-4529-840e-bb1a8e679437

This works when I am using standard Http Endpoint Functions but not Durable Functions, any help would be appriciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
{count} votes

2 answers

Sort by: Most helpful
  1. Rakesh Mishra 3,625 Reputation points Microsoft External Staff Moderator
    2025-11-26T17:39:16.59+00:00

    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:

    1. 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 required functions.metadata, deps.json, and runtimeconfig.json files. Without it, the project is just a standard Console App that doesn't know how to run as a Function App.
    2. 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).

    1. 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>
              
        
    2. 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.Sdk here (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>
        
    3. Program.cs (In Main Project) :
      Ensure your Program.cs is 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();
      
    0 comments No comments

  2. EnenDaveyBoy 71 Reputation points
    2025-12-04T09:47:45.57+00:00

    thanks got it sorted, changed my core lib to not have azure funcntion reference but only the modules it nneeds like logging and DI, then moved the none endpoint task references to core.endpoint and kept the endpoint only reference in the functions, i didn't release that the end point sdk reference had to be reference in the azure function csproj.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.