mnj
mnj

Reputation: 3413

Getter methods of EF not found in Azure Function

I'm trying to use Entity Framework inside Azure Function. I created my model locally and created a DLL of it - I tried using it in a Console Project and it works without issues.

I wanted to do the same in Azure Function, so I uploaded my DLL to bin folder of a function and added a reference in the code:

#r ".\bin\IoTDataModel.dll" 

I also added EntityFramework to the functon itself and refereced it:

using System.Data.Entity;
using System.Data.Entity.SqlServer;  
using System.Data.Entity.ModelConfiguration.Conventions;

I wrote some code, which uses the models that I have in my DLL and compilation goes fine. The problem appears during runtime. Exemplary code:

using (var context = new IoTDataBaseContext())
{
    var dev = context.Device.FirstOrDefault();
}

throws this error:

mscorlib: Exception has been thrown by the target of an invocation. f-EventHubMessageHandler__741454837: Method not found: 'System.Data.Entity.DbSet`1 IoTDataModel.IoTDataBaseContext.get_Device()'

"Device" is one of the models that I have in EntityFramework. generally i can't access any of my models, the error is always thrown. What might be the problem here?

Upvotes: 0

Views: 148

Answers (1)

DavidG
DavidG

Reputation: 118947

From a related GitHub issue:

if the assembly is properly versioned (i.e. the assembly identity changes as you change the types), this should work as expected and the new version will be resolved. Otherwise; you'll need to restart the function app to resolve the assembly. Deleting the function app is not required.

So restarting your function should do the job for now, but you should probably look into versioning your assembly to prevent this happening again.

Upvotes: 2

Related Questions