Debugging Azure Functions Locally with IronPDF

Issues when Running Azure Locally

A common exception seen when encountering this issue is "Error while locating deployment configuration file IronPdf.Native.Chrome.deployment.json"

Recommended: Run Windows-hosted Azure Function Apps that target .NET Core 3.1 <TargetFramework>netcoreapp3.1</TargetFramework>

Required: Use the default "in-process" configuration when creating an Azure Function in Visual Studio. The latest version of IronPDF supports Azure Functions running 'out-of-process' or in an 'isolated process,' as described in the "Guide for running C# Azure Functions in the isolated worker model." However, older versions might not support these types of Azure Functions.

Azure Function Diagram

Issue with Dependencies when Running Azure Functions Locally

When running Azure locally, using Azurite (VS2022) or the Azure Storage Emulator (VS2019), an additional bin directory is created that the Storage Emulator uses for deployment. Only DLL files are copied to this directory, so software that requires additional files will not function and may throw the above exception.

You may resolve this issue by copying the runtimes directory into the separate bin directory used by the Storage Emulator. We recommend doing this as a post-build event (see below for instructions) when running locally (as recompiling/building will return the bin directory to its original state). You will not encounter this issue when deploying to the cloud.

  • Problem: When running an Azure Function project locally, it creates an additional bin folder which it runs the function out of. However, it does not copy all of the necessary files into said bin folder.
  • Example: A project at C:\code\azure-functions-test that builds to C:\code\azure-functions-test\bin\Debug\netcoreapp3.1
  • Solution: Copy the C:\code\azure-functions-test\bin\Debug\netcoreapp3.1\runtimes directory so it also exists within C:\code\azure-functions-test\bin\Debug\netcoreapp3.1\bin
  • Overwrite any existing files if prompted

Dependency Diagram

Post-Build Event

To automate the process of copying necessary files into the local Azure Function bin directory, follow these instructions to set up a post-build event in Visual Studio:

  1. Right-click on the Azure Functions project, select Properties.
  2. Scroll down to the Events section.
  3. Enter a Post-build event as shown below:
XCOPY "$(TargetDir)runtimes" "$(TargetDir)bin\runtimes" /S /E /Y /I /R /D
XCOPY "$(TargetDir)runtimes" "$(TargetDir)bin\runtimes" /S /E /Y /I /R /D
SHELL

This command will:

  • Copy the contents of the runtimes directory into the bin/runtimes directory.
  • The /S and /E switches ensure all subdirectories and empty directories are included.
  • The /Y switch suppresses prompting to confirm you want to overwrite an existing destination file.
  • The /I switch assumes that the destination is a directory if it does not exist.
  • The /R switch overwrites read-only files.
  • The /D switch copies files changed on or after the specified date.

Post-Build Event Configuration