Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.93k stars 441 forks source link

Microsoft.Azure.KeyVault (Microsoft.Azure.Services.AppAuthentication) issue on functions runtime 2.0.11651-alpha #2852

Open Bubeee opened 6 years ago

Bubeee commented 6 years ago

Hi, I'm developing Azure Functions v2 in Visual Studio with latest tools installed. (.NET Core)

After an attempt to apply Azure KeyVault secrets to my functions (like described here https://medium.com/statuscode/getting-key-vault-secrets-in-azure-functions-37620fd20a0b) I've faced with issue on startup of function app in Azure. Kudu logs dump says the following:

Hosting environment: Production
Content root path: D:\Program Files (x86)\SiteExtensions\Functions\2.0.11651-alpha
Now listening on: http://localhost:12938
Warning: Only got partial types from assembly: MiddleWare.External.Functions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Exception message: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.Azure.WebJobs.Host.Indexers.DefaultTypeLocator.FindTypes(Assembly assembly, IEnumerable`1 extensionAssemblies) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\DefaultTypeLocator.cs:line 120

Investigative information

Repro steps

Provide the steps required to reproduce the problem:

Expected behavior

  1. Azure Functions working, retrieving secrets from the Key Vault instance on demand, correctly authenticating in Azure AD.

Actual behavior

Azure functions not starting, manual triggering causes 400 error. Kudu log dump provided above.

Known workarounds

Implementing custom Token Provider like on the screen below resolves the issue. image

So I think the issue is in the AppAuthentication package. I've debugged functions remotely in visual studio, but unfortunately it takes a lot of time to attach, and filter all not related exceptions during the debugging of actual issue with AzureServiceTokenProvider.

As soon as I got rid of the Microsoft.Azure.Services.AppAuthentication dependency, functions are able to start.

Now, switching to v1 version and will implement it there. So, not waiting for a quick answer, just want to recollect the thoughts and maybe I've missed something.

Bubeee commented 6 years ago

Migrated to Functions v1 and faced with the same issue.

2018-05-15T14:08:25 Welcome, you are now connected to log-streaming service. 2018-05-15T14:08:26.569 [Info] Function started (Id=10e4932a-705f-4879-bb00-db2a6857e3c7) 2018-05-15T14:08:26.585 [Info] C# Timer trigger function executed at: 5/15/2018 2:08:26 PM 2018-05-15T14:08:26.632 [Error] Function completed (Failure, Id=10e4932a-705f-4879-bb00-db2a6857e3c7, Duration=60ms)

After applying this code:

image

UPDATE: After some time it magically became working =\

paulbatum commented 6 years ago

What can you tell us about the assembly MiddleWare.External.Functions? This error message about partial types is not familiar. Is there something unusual about this assembly?

Bubeee commented 6 years ago

@paulbatum hi, If talking about the first attempt with Functions v2, it's casual Functions project.

image