6

I am trying to use Microsoft.AspNetCore.Authentication.Facebook with an Azure functions project. I created a completely clean .net core 3.1 Azure Function project only with the following dependencies:

Microsoft.NET.Sdk.Functions 3.0.7
Microsoft.Azure.Functions.Extensions 1.0.0
Microsoft.AspNetCore.Authentication.Facebook 3.1.5

In the startup file I have the following code:

 public override void Configure(IFunctionsHostBuilder builder)
 {           
     facebookOptions.AppId = Environment.GetEnvironmentVariable("Authentication:Facebook:AppId");
     facebookOptions.AppSecret = Environment.GetEnvironmentVariable("Authentication:Facebook:AppSecret");
 });

When I run the application I get the following error in the console window:

> A host error has occurred during startup operation Could not load file
> or assembly 'Microsoft.AspNetCore.Authentication.Facebook,
> Version=3.1.5.0, Culture=neutral, PublicKeyToken='. The system cannot
> find the file specified.

Any idea what could be wrong?

doorman
  • 15,707
  • 22
  • 80
  • 145

2 Answers2

1

After I added the user secrets library, debugging stopped working so I spent some time installing different versions of the Azure Functions sdk.

This may only be happening in my project but I decided to share the trial and error summary since this was really time consuming and just in case someone else will be having the same problem.

Microsoft.NET.SDK.Functions version 3.0.5 - 3.0.7
Resulted in the host error has occurred during startup operation Could not load file 

Microsoft.NET.SDK.Functions version 3.0.4
Resulted in FunctionsStartup not being called and debugging not triggering

Microsoft.NET.SDK.Functions version 3.0.3
Seems to be working with debugging and no error messages

Version 3.0.3 seems to work so far with debugging and no host error. So I am sticking with this version for now, hopefully it will be resolved in future releases.

Here are the dependencies I have in my solution.

enter image description here

doorman
  • 15,707
  • 22
  • 80
  • 145
0

There are two ways to troubleshooting:

  1. Add binding Redirect element in config file.

    <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
         <assemblyIdentity name="Microsoft.AspNetCore.Authentication.Facebook" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
         <bindingRedirect oldVersion="3.1.4" newVersion="3.1.5" />
       </dependentAssembly>
     </assemblyBinding>
    

    This specifies which version of assembly to use instead of old version. It is not necessarily requires later version be specified in newVersion, earlier version can be provided as well in newVersion.

  2. Update NuGet Package

    Update NuGet package in all root project and then in subsequent referred project (if required) where same package is referred.

For more details, you could refer to this article.

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Hi @JoeyCai thanks for the suggestion. It´s finally working, I think the error came after I manually updated to Azure Functions v3 in the project file instead of choosing the right template (Azure Function v3) upon project creation. – doorman Jun 18 '20 at 12:58