azure-functions-host: System.MissingMethodException: Method not found: Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration.get_SigningKeys()

Repro steps

Provide the steps required to reproduce the problem:

  • Ensure you have Azure Functions V3 func CLI from Github releases and .NET Core 3.1 SDK

  • > dotnet --version 3.1.401

  • > func --version 3.0.2798

  • > mkdir Assembler and > cd Assembler

  • > dotnet new classlib -n Assembler.Lib55 (Create new class library)

    • cd Assembler.Lib55
    • dotnet add package Microsoft.IdentityModel.Protocols.OpenIdConnect --version 5.5.0
    • Create a class named Lib55Class with following code snippet
       namespace Assembler.Lib55
       {
           public class Lib55Class
           {
               public async Task ReturnNothing()
               {
                   var metadataAddress ="https://justformajidstests.b2clogin.com/justformajidstests.onmicrosoft.com/B2C_1_DUMMY/v2.0/.well-known/openid-configuration";
                   var configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(
                           metadataAddress,
                           new OpenIdConnectConfigurationRetriever(),
                           new HttpDocumentRetriever()
                       );
                   var config = await configurationManager.GetConfigurationAsync(CancellationToken.None).ConfigureAwait(false);
                   var signingKeys = config.SigningKeys;
               }
           }
       }
    
  • > dotnet new classlib -n Assembler.Lib56 (Create new class library)

    • cd Assembler.Lib56
    • dotnet add package Microsoft.IdentityModel.Protocols.OpenIdConnect --version 5.6.0
    • Create a class named Lib56Class with similar code snippet
       namespace Assembler.Lib56
       {
           public class Lib56Class
           {
               public async Task ReturnNothing()
               {
                   var metadataAddress ="https://justformajidstests.b2clogin.com/justformajidstests.onmicrosoft.com/B2C_1_DUMMY/v2.0/.well-known/openid-configuration";
                   var configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(
                           metadataAddress,
                           new OpenIdConnectConfigurationRetriever(),
                           new HttpDocumentRetriever()
                       );
                   var config = await configurationManager.GetConfigurationAsync(CancellationToken.None).ConfigureAwait(false);
                   var signingKeys = config.SigningKeys;
               }
           }
       }
    
  • > func init Assembler.Functions --dotnet

    • Update nuget Microsoft.NET.Sdk.Functions to 3.0.9 and add MSBuild property <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> to Assembler.Functions.csproj
    • Add project reference to both class libraries. > dotnet add reference ../Assembler.Lib55 and dotnet add reference ../Assembler.Lib56
  • Create a new class Debug.cs with this code snippet

namespace Assembler.Functions
{
    public static class Debug
    {
        [FunctionName(nameof(Debug))]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "debug")] HttpRequest req,
            ILogger log)
        {
            var c55 = new Lib55Class();
            await c55.ReturnNothing().ConfigureAwait(false);

            //NOTE: If the following line is removed/commented out, the exception may not always happen!
            var assembly = Assembly.GetAssembly(typeof(OpenIdConnectConfiguration));

            var c56 = new Lib56Class();
            await c56.ReturnNothing().ConfigureAwait(false);
            return new OkResult();
        }
    }
}
  • > func start and invoke API http://localhost:7071/api/debug method_not_found_functions

Expected behavior

HTTP Status code should be 200

Actual behavior

HTTP Status is 500 with an exception

System.Private.CoreLib: Exception while executing function: Debug. Assembler.Lib55: Method not found: 'System.Collections.Generic.ICollection`1<Microsoft.IdentityModel.Tokens.SecurityKey> Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration.get_SigningKeys()'.

Known workarounds

None

Related information

Provide any related information

  • Programming language used: C#
  • Bindings used: HTTPTrigger

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

This is an awesome repro, thank you! I’m looking at it now.

Oh I should note – tomorrow morning I’m going to investigate a workaround for you. It may involve you force-loading types from these “higher-versioned” assemblies early in your process.

And thank you IMMENSELY for this repro – this is a complicated scenario and you made it a lot simpler to work with. I really appreciate that.

My colleague, Majid (@themajix) created a github repo with more details.

Repo: https://github.com/themajix/mutiversion_assemblies_in_functions