Azure function won't run with "Could not load file or assembly" error

Rainer 166 Reputation points
2023-06-23T09:09:05.5966667+00:00

I'm updating my Azure functions from v3 to v4, updating to .NET 7, and moving to running as isolated worker process. I've made all the necessary code changes and it compiles fine, but when I try to run I get this error:

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'BeerApp.ServiceFunctions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

I've searched for similar problems, but they all refer to problems loading specific assemblies like Microsoft libraries or 3rd party libraries, but In this case BeerApp.ServiceFunctions is the assembly for my Azure functions.

I'm guessing some dependency that my functions rely on is the root problem, but I how can I diagnose this? Is there anyway to get more info on why it can't load? I've tried adding --verbose when I run via func run --verbose, but that didn't give any useful info.

Any suggestions would be appreciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2023-06-26T04:13:17.9233333+00:00

    Hi Rainer

    I'm glad to see you were able to resolve your issue. Thanks for posting your solution so that others experiencing the same thing can easily reference this.

    Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer, they can only accept answers by others, I'll repost your solution in case you'd like to Accept the answer.

    Issue: You're using Terraform to create Azure Function instance which then pulls your app code from a container registry. After image pull, the function app failed to load.

    Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'BeerApp.ServiceFunctions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

    Resolve: You found that in your .csproj file you have the below property element. After removing the below content, the issue was resolved.

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    		<PlatformTarget>x64</PlatformTarget>
    </PropertyGroup>
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Rainer 166 Reputation points
    2023-06-24T08:44:56.6366667+00:00

    I figured out the problem. For some reason I had the following in my .csproj file. After removing it the problem went away.

    	<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    		<PlatformTarget>x64</PlatformTarget>
    	</PropertyGroup>
    
    0 comments No comments

Your answer

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