Please provide the following:
Provide the steps required to reproduce the problem:
I'm using Microsoft.IdentityModel.Clients.ActiveDirectory nuget package version 3.19.1 to connect authenticate to Azure Batch
The auth code is :
public static async Task<string> GetAuthenticationTokenAsync(string tenantId, string clientId, string clientKey)
{
AuthenticationContext authContext = new AuthenticationContext(_AuthorityUri + tenantId);
AuthenticationResult authResult = await authContext.AcquireTokenAsync(_BatchResourceUri, new ClientCredential(clientId, clientKey));
return authResult.AccessToken;
}
Exception message is :
Exception while executing function: GetTaskCounts Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.1.3001, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.1.3001, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Whenever this code is called there is an exception being raised with the below stack
Microsoft.Azure.WebJobs.Host.FunctionInvocationException:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__16.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 320)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+
Inner exception System.IO.FileLoadException handled at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw:
at BatchHelpers.Auth.GetAuthenticationTokenAsync (BatchHelpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null)
at BatchMonitorFunctions.GetTaskCounts+<>c.
at Microsoft.Azure.Batch.Protocol.BatchTokenProvider+
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Rest.TokenCredentials+<ProcessHttpRequestAsync>d__17.MoveNext (Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Batch.Protocol.JobOperations+<ListWithHttpMessagesAsync>d__14.MoveNext (Microsoft.Azure.Batch, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Batch.Protocol.BatchRequestBase2+
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Batch.Protocol.BatchRequestBase2+<ExecuteRequestAsync>d__40.MoveNext (Microsoft.Azure.Batch, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Batch.Protocol.BatchRequestBase2+
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Batch.ProtocolLayer+1.MoveNext (Microsoft.Azure.Batch, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Batch.AsyncListJobsEnumerator+<GetNextBatchFromServerAsync>d__8.MoveNext (Microsoft.Azure.Batch, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Batch.PagedEnumeratorBase1+
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Batch.PagedEnumeratorBase1.MoveNext (Microsoft.Azure.Batch, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at BatchHelpers.MonitorOperations+<LogAllJobsTaskCounts>d__4.MoveNext (BatchHelpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullBatchHelpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\xpillons\Source\Repos\nemo\CloudCompute\BatchHelpers\MonitorOperations.csBatchHelpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 34)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at BatchMonitorFunctions.GetTaskCounts+<Run>d__0.MoveNext (BatchMonitorFunctions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullBatchMonitorFunctions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\xpillons\Source\Repos\nemo\CloudCompute\BatchMonitorFunctions\GetTaskCounts.csBatchMonitorFunctions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 37)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker2+
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker2+
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<InvokeAsync>d__24.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 583)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithWatchersAsync>d__23.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 534)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__22.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 477)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__16.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 264)
Inner exception System.IO.FileLoadException handled at BatchHelpers.Auth.GetAuthenticationTokenAsync:
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Reflection.Assembly.LoadFrom (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Reflection.Assembly.LoadFromResolveHandler (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.AppDomain.OnAssemblyResolveEvent (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
Provide a description of the expected behavior.
Provide a description of the actual behavior observed.
No Workaround
Provide any related information
I was only able to resolve this by enabling Managed Service Identity (MSI) on the function app service.
@baabel I don't know how you do this in the context of Batch as you need creds to open a Batch client
Func<Task<string>> tokenProvider = () => Auth.GetAuthenticationTokenAsync(Environment.GetEnvironmentVariable("TenantId"), Environment.GetEnvironmentVariable("ClientId"), Environment.GetEnvironmentVariable("ClientKey"));
BatchTokenCredentials creds = new BatchTokenCredentials(Environment.GetEnvironmentVariable("BatchAccountUrl"), tokenProvider);
_client = await BatchClient.OpenAsync(creds);
I have the same problem with an Azure function which tries to run an Azure Data Factory from the code, and when trying to get credentials, this error pops up.
This was mitigated in production. Can you confirm you're still seeing the issue?
@hatuar , is this when deployed or when running locally?
Encountering the same issue with Function + MSI
2018-02-26T18:54:53.472 [Info] {
"authorization": "{\"scope\":\"/subscriptions/<subscription-id>/resourcegroups/bp-eventgrid-test1/providers/Microsoft.Network/networkInterfaces/dynamic13\",\"action\":\"Microsoft.Network/networkInterfaces/write\",\"evidence\":{\"role\":\"Subscription Admin\"}}",
"claims": "{\"aud\":\"https://management.core.windows.net/\",\"iss\":\"https://sts.windows.net/<aad-tenant-id>/\",\"iat\":\"1519668625\",\"nbf\":\"1519668625\",\"exp\":\"1519672525\",\"http://schemas.microsoft.com/claims/authnclassreference\":\"1\",\"aio\":\"Y2NgYNhWcDP132X5Bh4xj6lxjJPUuyL2mF8Pt3EWVWPu8HVwcAcA\",\"http://schemas.microsoft.com/claims/authnmethodsreferences\":\"pwd\",\"appid\":\"04b07795-8ddb-461a-bbee-02f9e1bf7b46\",\"appidacr\":\"0\",\"e_exp\":\"262800\",\"groups\":\"8ee63294-6dcf-45b5-abd7-eb13979ce39a\",\"ipaddr\":\"86.183.165.147\",\"name\":\"vsts\",\"http://schemas.microsoft.com/identity/claims/objectidentifier\":\"f4c5a56b-cd28-482d-ae3d-28dc6d774132\",\"puid\":\"10033FFFA8B40B2E\",\"http://schemas.microsoft.com/identity/claims/scope\":\"user_impersonation\",\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\":\"Cxj8gl_cUfk9ZsxybjWA2Zxydqf5_7VdHgc7fEy59R0\",\"http://schemas.microsoft.com/identity/claims/tenantid\":\"<aad-tenant-id>\",\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\":\"[email protected]\",\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn\":\"[email protected]\",\"uti\":\"HeCuqKN450CaH3A6cwMcAA\",\"ver\":\"1.0\",\"wids\":\"62e90394-69f5-4237-9190-012177145e10\"}",
"correlationId": "e6869a1d-9566-4ff1-9522-84eefcfb88fe",
"httpRequest": "{\"clientRequestId\":\"bc3d2f54-d96a-49e7-a88f-1a5cded6a63a\",\"clientIpAddress\":\"86.183.165.147\",\"method\":\"PUT\",\"url\":\"https://management.azure.com/subscriptions/<subscription-id>/resourcegroups/bp-eventgrid-test1/providers/Microsoft.Network/networkInterfaces/dynamic13?api-version=2015-05-01-preview\"}",
"resourceProvider": "Microsoft.Network",
"resourceUri": "/subscriptions/<subscription-id>/resourcegroups/bp-eventgrid-test1/providers/Microsoft.Network/networkInterfaces/dynamic13",
"operationName": "Microsoft.Network/networkInterfaces/write",
"status": "Succeeded",
"subscriptionId": "<subscription-id>",
"tenantId": "<aad-tenant-id>"
}
2018-02-26T18:54:54.575 [Error] Function completed (Failure, Id=2f547f0d-ffb1-4791-8b00-a2d95272c183, Duration=1218ms)
2018-02-26T18:54:54.575 [Error] Exception while executing function: changedynamiciptostaticip2
2018-02-26T18:54:54.575 Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
2018-02-26T18:54:54.575 [Error] Function completed (Failure, Id=2f547f0d-ffb1-4791-8b00-a2d95272c183, Duration=1218ms)
2018-02-26T18:54:54.575 [Error] Executed 'changedynamiciptostaticip2' (Failed, Id=2f547f0d-ffb1-4791-8b00-a2d95272c183)
2018-02-26T18:54:54.575 Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
2018-02-26T18:54:54.575 [Error] Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is '2f547f0d-ffb1-4791-8b00-a2d95272c183'
2018-02-26T18:54:54.575 Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
@fabiocav Hi, I'm experiencing the same issue with Microsoft.IdentityModel.Clients.ActiveDirectory version 3.16.0.14 when deployed to Azure. It works fine when run locally.
System.IO.FileLoadException : Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.16.0.14, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) ---> System.IO.FileLoadException : Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.16.0.14, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext,String ilPath,String niPath,ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at System.Reflection.Assembly.LoadFromResolveHandler(Object sender,ResolveEventArgs args)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly,String assemblyFullName)
Project file packages:
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.16.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0-rtm-rc7" />
@fabiocav
I met the same issue when using Version 3.16.0.14 of Microsoft.IdentityModel.Clients.ActiveDirectory, it works normally on local but when deploy on Azure Functions it's bug as below:
Exception while executing function: INSQualifyProcess
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: INSQualifyProcess ---> System.IO.FileLoadException : Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.16.0.14, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) ---> System.IO.FileLoadException : Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.16.0.14, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext,String ilPath,String niPath,ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at System.Reflection.Assembly.LoadFromResolveHandler(Object sender,ResolveEventArgs args)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly,String assemblyFullName)
It seem okay when i downgrade version of Microsoft.IdentityModel.Clients.ActiveDirectory to 3.14. Deploy it to Azure Functions and it works, maybe it's caused by library bug.
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.14.0" />
After running into this problem in one project but it working in another, there is something else you can try, which is "downgrading" to the full framework and the previous version of Azure Functions.
To do this, change the TargetFramework in .csproj to net461 and remove the line <AzureFunctionsVersion>v2</AzureFunctionsVersion>.
If you do not remove the v2 line, you will get a blunt Fatal Error when you try to run the function.
This was my situation and what worked for me:
I was using the Microsoft.IdentityModel.Clients.ActiveDirectory version 3.19 in a class library project but only had version 2.22 installed in the actual ASP.NET Web Application project. Upgrading to 3.19 in the web app project got me past the error.
We are experiencing this exact same issue, for a C# compiled function targeting .NET Core (Azure Functions v2), running the function locally, with Microsoft.IdentityModel.Clients.ActiveDirectory v3.19.4
arning: Only got partial types from assembly: TokenExpiration, 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.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
[5/8/18 9:37:56 PM] Generating 0 job function(s)
[5/8/18 9:37:56 PM] Error indexing method 'TokenExpiration.RunAsync'
[5/8/18 9:37:56 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'TokenExpiration.RunAsync'. System.Private.CoreLib: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.4.11002, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.4.11002, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
We had to downgrade to 3.14.0, as recommended by @phinguyenit
dotnet remove TokenExpiration package Microsoft.IdentityModel.Clients.ActiveDirectory
dotnet add TokenExpiration package Microsoft.IdentityModel.Clients.ActiveDirectory --version 3.14.0
Update: It seems that 3.16.0 is the most recent version that does not cause an issue.
dotnet add TokenExpiration package Microsoft.IdentityModel.Clients.ActiveDirectory --version 3.16.0
Starting with 3.16.1 and on, we experience this issue.
I have the same issue with Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.8.16603
When I have 3.19 installed framework asks for 3.14
When I downgrade to 3.14 frameworks says that 3.19 is needed.
Azure Functions in local emulator .NET 4.7.2
@gotgenes do you continue to experience this issue with the most recent version of the Azure Functions host and core tools?
@mchudinov can you provide more information on your scenario? This seems to be with V1, which is different than what originally reported on this issue. Could you open a different issue with your error details, exact core tools version and details about your configuration (or a repro)? Thanks!
I've run into this same issue when deploying with 3.14. Has anybody run into this same problem with the latest version?
Couldn't get this working in Azure Functions. So recreated the fuction in Visual studio then downloaded each assembly. These gave the correct versions for the dependencies. You can see that in the dependencies in the VS project. I then ammended the version numbers in the azure function project file. Easy when you know how, not easy when you are a newbee.
Hi, I also got the same bug, it is because they have Active directory lib installed in different version.
Install all the Active directory in same version like 3.18 will solve this.
Just got exceptions on this as well.
When using Azure Functions v1 with Azure ServiceBus v3.4.0, we can't even downgrade the ActiveDirectory Assembly to 3.14.0 or 3.16.0 as suggested, as the ServiceBus package requires at least v3.17.2.
Any hints on this?
So, turns out when you use your Azure Function for connecting against Dynamics CRM and use the XrmTooling Assemblies, you even need to set Microsoft.IdentityModel.Clients.ActiveDirectory to v2.22.302111727, as this is the version that the CRM SDK requires.
It's been two years & we don't have any update?
I am facing this along with "Microsoft.Azure.Kusto.Data.NETStandard" lib. Azure function works with 3.14 but this one needs min 4.5.1. So eventually I cant call kusto from Azure function.
It's been two years & we don't have any update?
I am facing this along with "Microsoft.Azure.Kusto.Data.NETStandard" lib. Azure function works with 3.14 but this one needs min 4.5.1. So eventually I cant call kusto from Azure function.
Did you get this resolved another way?
Edit: I was able to resolve this by removing 'Az' = '4.*' from the requirements.psd1 file. It looks like some of the Az modules in v4 load an old version of ADAL.
I also get the error when trying to fetch a certificate from the store. I am targeting .net core 3.1.
I have version 5.7.2 installed
this is my 'program' code:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
var builtConfig = config.Build();
//for some reason this blows up??
config.AddAzureKeyVault(
$"https://{builtConfig["KeyVault:Name"]}.vault.azure.net/",
builtConfig["AzureAd:ClientId"],
GetCertificate(builtConfig["Asymmetric:CertificateThumbprint"]));
})
this is the method for retrieving the certificate from the store:
```
private static X509Certificate2 GetCertificate(string thumbprint)
{
var store = new
X509Store(StoreName.My, StoreLocation.CurrentUser);
try{
store.Open(OpenFlags.ReadOnly); var certificateCollection =
store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (certificateCollection == null || certificateCollection.Count == 0)
{
throw new ArgumentException("certificate was not found in store");
}
return certificateCollection[0];
}
finally
{
// Close is private in DNXCORE, but Dispose calls close internally
store.Dispose();
}
}```
and lastly this is the error i get:


with stacktrace:
at Microsoft.Extensions.Configuration.AzureKeyVault.AzureKeyVaultConfigurationOptions.<GetTokenFromClientCertificate>d__20.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.Extensions.Configuration.AzureKeyVault.AzureKeyVaultConfigurationOptions.GetTokenFromClientCertificate(String authority, String resource, String clientId, X509Certificate2 certificate)
at Microsoft.Extensions.Configuration.AzureKeyVault.AzureKeyVaultConfigurationOptions.<>c__DisplayClass1_0.<.ctor>b__0(String authority, String resource, String scope)
at Microsoft.Azure.KeyVault.KeyVaultCredential.<PostAuthenticate>d__11.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Azure.KeyVault.KeyVaultCredential.<ProcessHttpRequestAsync>d__13.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.KeyVault.KeyVaultClient.<GetSecretsWithHttpMessagesAsync>d__67.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Azure.KeyVault.KeyVaultClientExtensions.<GetSecretsAsync>d__50.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Extensions.Configuration.AzureKeyVault.AzureKeyVaultConfigurationProvider.<LoadAsync>d__11.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Extensions.Configuration.AzureKeyVault.AzureKeyVaultConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at WebClient.Program.Main(String[] args) in ....\Program.cs:line 17
I might be overlooking something but to me it seems like a library bug.
This issue seems to be referred to in several posts, does anyone have a workaround for .net core requiring version 3.14.2?
Most helpful comment
We are experiencing this exact same issue, for a C# compiled function targeting .NET Core (Azure Functions v2), running the function locally, with Microsoft.IdentityModel.Clients.ActiveDirectory v3.19.4
We had to downgrade to 3.14.0, as recommended by @phinguyenit
Update: It seems that 3.16.0 is the most recent version that does not cause an issue.
Starting with 3.16.1 and on, we experience this issue.