Out of Memory exception on a function app hosted in Azure

Newbie Dev 151 Reputation points
2022-10-19T13:53:43.21+00:00

Hi,
I have an azure Function(v4,.net6), which occasionally shows the below error.

System.OutOfMemoryException:  
   at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=****)  
   at lambda_method459 (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)  
   at DryIoc.Scope.TryGetOrAdd (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:7849)  
   at DryIoc.Scope.GetOrAdd (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:7834)  
   at lambda_method458 (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)  
   at DryIoc.Scope.TryGetOrAdd (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:7849)  
   at DryIoc.Scope.GetOrAdd (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:7834)  
   at lambda_method457 (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)  
   at DryIoc.Scope.TryGetOrAdd (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:7849)  
   at DryIoc.Scope.GetOrAdd (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:7834)  
   at lambda_method456 (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)  
   at DryIoc.Scope.TryGetOrAdd (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:7849)  
   at DryIoc.Scope.GetOrAdd (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:7834)  
   at lambda_method455 (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)  
   at DryIoc.Container.ResolveAndCacheDefaultFactoryDelegate (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:224)  
   at DryIoc.Container.DryIoc.IResolver.Resolve (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/DryIoc/Container.cs:195)  
   at Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.ScopedServiceProvider.GetService (Microsoft.Azure.WebJobs.Script.WebHost, Version=4.13.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script.WebHost/DependencyInjection/ScopedServiceProvider.cs:25)  
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService (Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=****)  
   at lambda_method371 (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)  
   at Microsoft.Azure.WebJobs.Host.Executors.DefaultJobActivator.CreateInstance (Microsoft.Azure.WebJobs.Host, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\DefaultJobActivator.cs:42)  
   at Microsoft.Azure.WebJobs.Host.Executors.DefaultJobActivator.CreateInstance (Microsoft.Azure.WebJobs.Host, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\DefaultJobActivator.cs:31)  
   at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory`1+<>c__DisplayClass1_1.<.ctor>b__0 (Microsoft.Azure.WebJobs.Host, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs:20)  
   at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory`1.Create (Microsoft.Azure.WebJobs.Host, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs:25)  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.CreateInstance (Microsoft.Azure.WebJobs.Host, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:44)  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+ParameterHelper.Initialize (Microsoft.Azure.WebJobs.Host, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:791)  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<TryExecuteAsync>d__18.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:104)  

Not sure if this is related, but the Function app uses GraphServiceClient class (Graph API). The class does not have an interface, so I have created an interface which implements the creation of the service client. The interface is registered as scoped.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,487 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,059 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,446 Reputation points
    2022-10-20T08:51:31.63+00:00

    Hi @Newbie Dev ,

    Please check if the below post helps in resolving the issue.

    https://learn.microsoft.com/en-us/answers/questions/931451/function-app-gives-outofmemory-error.html?childToView=932016#answer-932016

    Feel free to reach out to me if you have any questions.