Entity Framework 6.4 throwing NullReferenceException with Azure Functions V3

0

I'm using Azure Functions V3 (.Net Core 3.1) and trying to call an Entity FrameWork class built using EF 6.4 (.Net 7.2) and Entity Framework is throwing a NullReferenceException. The same call succeeds while using .Net Core console app instead of Azure Function. Appreciate your help here.

Here is my function definition:

namespace FunctionAppV32 
{
    public static class Function1 
    {
        [FunctionName("Function1")] 
        public static void Run([TimerTrigger("0 * * * * *")]TimerInfo myTimer, ILogger log) 
        { 
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); 

            var cstr = ConnectionString2.BuildConnectionString(); 
            FlighterSIEntities entities = new FlighterSIEntities(cstr); 

            foreach (var x in entities.TGBotComplexVectorParamSettings) 
            { .... }
        }
    }
}

The exception is thrown while accessing entities.TGBotComplexVectorParamSettings in for loop.

Exception Stack Trace:

System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=EntityFramework StackTrace:

at System.Data.Entity.Core.EntityClient.EntityConnection.GetStoreConnection(DbProviderFactory factory)
at System.Data.Entity.Core.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.Entity.Core.EntityClient.EntityConnection..ctor(String connectionString) at System.Data.Entity.Internal.LazyInternalConnection.Initialize() at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() at FunctionAppV32.Function1.Run(TimerInfo myTimer, ILogger log) in D:\src\RnR-ExperimentationTools\src\TGBot\FunctionAppV32\Function1.cs:line 20 at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker2.InvokeAsync(TReflected instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\VoidMethodInvoker.cs:line 20 at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.d__10.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52

entity-framework-6
azure-functions
asked on Stack Overflow Jan 31, 2020 by Venkata Praveen • edited Feb 1, 2020 by marc_s

1 Answer

0

I was able to resolve exactly same issue with updating below packages to mentioned versions. Hope it helps to you or anyone facing the same issue.

  • EntityFramework to Version=6.4.4
  • Microsoft.EntityFrameworkCore to Version=3.1.6
  • Microsoft.Extensions.Configuration to Version=3.1.6

Kindly check.

answered on Stack Overflow Jul 28, 2020 by S J • edited Jul 28, 2020 by S J

User contributions licensed under CC BY-SA 3.0