azure-functions-host icon indicating copy to clipboard operation
azure-functions-host copied to clipboard

Assembly conflict in Azure in process function v4

Open JoshLove-msft opened this issue 1 year ago • 13 comments

@xztmp1 commented on Wed Mar 01 2023

Library name and version

Azure.Data.AppConfiguration

Describe the bug

Azure.Data.AppConfiguration: Method 'AsPages' in type 'FuncAsyncPageable`1' from assembly 'Azure.Data.AppConfiguration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an implementation.

Expected behavior

We are converting a .net3.1 inprocess function to .net6 function v4. The assembly is getting resolved properly on the localhost, but when it is deployed to Azure fails with the following error Azure.Data.AppConfiguration: Method 'AsPages' in type 'FuncAsyncPageable`1' from assembly 'Azure.Data.AppConfiguration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an implementation.

Actual behavior

Azure.Data.AppConfiguration: Method 'AsPages' in type 'FuncAsyncPageable`1' from assembly 'Azure.Data.AppConfiguration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an implementation.

Reproduction Steps

These are the libraries referenced in the project file: "Azure.Identity" Version="1.4.1" "AzureExtensions.Swashbuckle" Version="3.3.2" "AspNetCore.HealthChecks.CosmosDb" Version="3.1.2" "Elevate.CacheServices.Client" Version="1.1.1" "FluentValidation" Version="10.3.3" "Microsoft.ApplicationInsights" Version="2.20.0" "Microsoft.Azure.Cosmos" Version="3.22.1" "Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.9" "Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="5.2.0" "Microsoft.Extensions.Logging" Version="6.0.0" "Microsoft.Extensions.Options.DataAnnotations" Version="6.0.0" "Microsoft.NET.Sdk.Functions" Version="4.1.1" "Newtonsoft.Json" Version="13.0.1"

Environment

No response


@jsquire commented on Wed Mar 01 2023

Thank you for your feedback. Tagging and routing to the team member best able to assist.


@JoshLove-msft commented on Wed Mar 01 2023

I found a StackOverflow post that describes this exact scenario and recommends adding an explicit dependency for Microsoft.Extensions.Configuration.Abstractions to 6.0.0, as the issue appears to be due to an incompatibilty with 7.x which is pulled in transitively via your Microsoft.Extensions.Configuration.AzureAppConfiguration reference. Would you be able to try this workaround?

@fabiocav Is there any other docs we can point customers to for this issue? Is the above workaround accurate to your knowledge? I can also move this issue over to the functions host repo.


@xztmp1 commented on Wed Mar 01 2023

I tried as per your suggestion, but I am getting the same error: Azure.Data.AppConfiguration: Method 'AsPages' in type 'FuncAsyncPageable`1' from assembly 'Azure.Data.AppConfiguration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an implementation.

Also this happens only on Azure run time. It works fine on my localhost all the time


@JoshLove-msft commented on Wed Mar 01 2023

@xztmp1 could you share a zip containing a minimal repo?


@xztmp1 commented on Thu Mar 02 2023

Sorry I won't be able to share the code as it has proprietary information. This is a simple Http trigger function


@JoshLove-msft commented on Thu Mar 02 2023

Given that this appears to be an issue with the dependency resolution happening on the function host, and not locally, I will go ahead and transfer this issue to the functions host repo. The functions team should be able to debug further including having access to any server logs that may help them track down the issue.

JoshLove-msft avatar Mar 02 '23 17:03 JoshLove-msft

I am running into a similar error getting configurations from Azure KeyVault:

Microsoft.Azure.WebJobs.Script.ExternalStartupException : Error configuring services in an external startup class. ---> System.TypeLoadException : Method 'AsPages' in type 'FuncAsyncPageable`1' from assembly 'Azure.Security.KeyVault.Secrets, Version=4.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an implementation.

This is coming up inconsistently when deploying our function app to Azure; some builds work and some don't.

HolisticDeveloper avatar May 08 '23 20:05 HolisticDeveloper

@HolisticDeveloper can you please open a separate issue with the details of what you're running into? Different assemblies (and the fact you're not seeing this consistently) would require a different investigation, and having those details would help.

@xztmp1 do you have a sample project that reproduces this issue? Would be great if you could share something so we don't miss anything about your setup. Azure.Data.AppConfiguration is not a unified assembly, and nothing in the host should interfere with the version you're loading, so it would be good to look at the build process and what is happening at runtime.

Thanks!

fabiocav avatar May 08 '23 22:05 fabiocav

@HolisticDeveloper Did you ever figure it out? I'm getting the exact same error message when deploying to AppService!

ChrisBurgdorff avatar Jun 13 '23 03:06 ChrisBurgdorff

@HolisticDeveloper Did you ever figure it out? I'm getting the exact same error message when deploying to AppService!

@ChrisBurgdorff In my case, after updating the app to ensure it was using v6 of Microsoft.Extensions.Configuration.Abstractions instead of v7, I had to stop the function app and restart it before it would work successfully.

HolisticDeveloper avatar Jun 14 '23 17:06 HolisticDeveloper

We are facing the same issue, in .NET 6.0 Azure Function App v4, sitting on EP1 Windows App Service Plan. When we are trying to connect to Key Vault using:

builder.AddAzureKeyVault(
          new Uri($"https://{builder.Build()["KeyVaultName"]}.vault.azure.net/"),
          new DefaultAzureCredential());

We get the following error:

Unhandled exception. System.TypeLoadException: Method 'AsPages' in type 'FuncAsyncPageable`1' from assembly 'Azure.Security.KeyVault.Secrets, Version=4.5.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an implementation.

at Azure.Core.PageResponseEnumerator.CreateAsyncEnumerable[T](Func`2 pageFunc)
at Azure.Security.KeyVault.Secrets.SecretClient.GetPropertiesOfSecretsAsync(CancellationToken cancellationToken)
at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.LoadAsync()
at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at ...

Steps we tried:

  1. Microsoft.Extensions.Configuration.Abstractions v6.0.0 was directly installed in FA project
  2. The same was done with Azure.Core (v1.32.0)
  3. All permissions are verified, FA has access to Key Vault.

Any clues or updates about this issue?

vtkachenko avatar Jun 16 '23 16:06 vtkachenko

@HolisticDeveloper Did you ever figure it out? I'm getting the exact same error message when deploying to AppService!

I have the same issue when configuring AppConfiguration with a Web App Service. Tried to explicitly reference Microsoft.Extensions.Configuration.Abstractions v6.0.0 as suggested without any success.

<PackageReference Include="Azure.Identity" Version="1.9.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
builder.Configuration
    .AddAzureAppConfiguration(options =>
    {
         options
             .Connect(
                 new Uri($"https://{builder.Configuration["AppConfiguration:Name"]}.azconfig.io"),
                 new DefaultAzureCredential())
             .ConfigureKeyVault(kv => kv.SetCredential(new DefaultAzureCredential())
             .Select(KeyFilter.Any, "SomeLabel")
             .ConfigureRefresh(refreshOptions =>
            {
                refreshOptions
                    .Register(RefreshKey, "SomeLabel", true)
                    .SetCacheExpiration(TimeSpan.FromDays(1));

                    builder.Services.AddSingleton(options.GetRefresher());
            })
    });

Tried to create a new app service as well, as the other one was upgraded from .NET 5 to .NET 6 to .NET 7, but didn't help either. Strangely enough we have another App Service, also running .NET 7 where the same configuration is working.

Smurfa avatar Jul 10 '23 13:07 Smurfa

Is there a solution for this issue? We're hitting it consistently and have tried all the potential workarounds in this thread.

ewwwgiddings avatar Aug 22 '23 16:08 ewwwgiddings

Ended up solving it by using <PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.24" /> package only (remove the others) and builderParam.ConfigurationBuilder.AddAzureKeyVault($"https://{kvConfig.VaultName}.vault.azure.net/", new DefaultKeyVaultSecretManager()). I looked in the Nuget package for the problem package here and saw that AddAzureKeyVault was using this package at the heart of it. So by only using this package it never needed to deal with the problem package which we weren't really using anyway.

ewwwgiddings avatar Aug 23 '23 14:08 ewwwgiddings

Hey, I see that the workaround was to use a different package and method is there a solution to this? we are facing the same issue but not with Azure functions - just regular app with attempt to connect to KV using the extention method AddAzureKeyVault

yossika-tr avatar Sep 24 '23 10:09 yossika-tr

Not sure if it help anyone, but having spent hours trying to solve this I thought I'd share. TLDR: Make sure the publish step in the build pipeline targets the main project instead of **/*.csproj.

Encountered this exact error message on a .NET console application (Hosted service, running as a Windows service).

For me the problem was solved by changing the build pipeline's publish step from; projects: '**/*.csproj' to the csproj-file of the default project of the solution, ex: projects: '**/Service.csproj.

My theory, after a lot of trial and error and adding direct references to all the Microsoft.Extensions.* 7.0 packages that it complained about, is that the publish step included things that testhost.exe needed (or some other build step part), and that conflicted with what the application needed.

Was easy to re-create in my scenario, downloading the artifacts from the build pipeline and trying to execute them locally gave the same error. (The error: "Method 'AsPages' in type 'FuncAsyncPageable1'" started showing itself after I'd added direct references to almost every Microsoft.Extensions.*`-package out there, so it felt anyway.. :-))

taxx avatar Nov 14 '23 14:11 taxx

@taxx Our team ran into this today and have spent all day trying to figure it out. None of the other suggestions of downgrading the packages worked. By some stroke of luck you posted a working fix the same day we ran into it, and so far this is the only time I've ever seen it suggested. Our pipeline's publish step was referencing the .sln file. Changing it to reference the .csproj of the default project fixed it. Thank you!

jesseperrone avatar Nov 14 '23 18:11 jesseperrone

I changed a docker file and published not .sln, but main .csproj and the issue has gone as well @taxx thank you, it saved me a whole day

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish  MyprojectName.csproj -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

se-trofimov avatar Nov 18 '23 00:11 se-trofimov

Not sure if it help anyone, but having spent hours trying to solve this I thought I'd share. TLDR: Make sure the publish step in the build pipeline targets the main project instead of **/*.csproj.

Encountered this exact error message on a .NET console application (Hosted service, running as a Windows service).

For me the problem was solved by changing the build pipeline's publish step from; projects: '**/*.csproj' to the csproj-file of the default project of the solution, ex: projects: '**/Service.csproj.

My theory, after a lot of trial and error and adding direct references to all the Microsoft.Extensions.* 7.0 packages that it complained about, is that the publish step included things that testhost.exe needed (or some other build step part), and that conflicted with what the application needed.

Was easy to re-create in my scenario, downloading the artifacts from the build pipeline and trying to execute them locally gave the same error. (The error: "Method 'AsPages' in type 'FuncAsyncPageable1'" started showing itself after I'd added direct references to almost every Microsoft.Extensions.*`-package out there, so it felt anyway.. :-))

This was actually the case for me. This would happen especially if you have projects on the same level as the application that you're trying to publish.

bmacalindong avatar Feb 16 '24 20:02 bmacalindong