question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Runtime Exception on Azure Functions with Entity Framework

See original GitHub issue

Hi, Team.

I’ve got an issue with running Azure Functions that references to EntityFramework. Here’s my SO Question:

http://stackoverflow.com/questions/40671391/azure-functions-with-entity-framework

I referenced an external assembly that are working perfectly fine on my existing application. This is actual implementation of EntityFramework for my database. When you have a look at the SO question above, I provided the complete code, project.json, and exception log details. Of course I copied the external assembly into the bin directory.

Can anyone have a look, please?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rndthoughtscommented, Mar 21, 2017

@govindsyadv - thanks, that works! So I assumed that by adding the Entity Framework package to the nuget file in my Functions project it would be enough for my satellite assembly to pick it up. But it isn’t, I need to copy the EF dll and all the other dll’s my satellite needs for operation. So I just greated a gulp file to copy all of them into the bin folder for my function.

Hopefully references will be something coming soon in the tooling.

2reactions
govindsyadvcommented, Mar 21, 2017

Hi ,

I am using the EF6 and it is working successfully . Apart from efconnection builder , you also need to copy the ef6 dll in the shared/bin folder and refer the dll / import in your csx file .

These are the snippets of my working code .

public MYDBContext() : base(GetConnectionString()) { }

    private static string GetConnectionString()

    {

        const string providerName = "System.Data.SqlClient";
        const string metadata = @"res://*/MYDB.csdl|res://*/MYDB.ssdl|res://*/MYDB.msl";

        string connectString = ConfigurationManager.ConnectionStrings["MYDBContext"].ToString();


        // Initialize the connection string builder for the
        // underlying provider.
        SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(connectString);

        // Set the properties for the data source.
        //sqlBuilder.IntegratedSecurity = true;
        sqlBuilder.MultipleActiveResultSets = true;

        // Build the SqlConnection connection string.
        string providerString = sqlBuilder.ToString();

        // Initialize the EntityConnectionStringBuilder.
        EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();

        //Set the provider name.
        entityBuilder.Provider = providerName;

        // Set the provider-specific connection string.
        entityBuilder.ProviderConnectionString = providerString;

        // Set the Metadata location.
        entityBuilder.Metadata = metadata;

        return entityBuilder.ConnectionString;

    }

here the connection string is set in application settings .

on csx part

using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Data.Entity.Core.Objects; using System.Data.Entity.ModelConfiguration.Conventions;

using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Net; using System.Configuration; using System.IO; using System.Net.Mail;

using Newtonsoft.Json.Linq; using Newtonsoft.Json;

public static void Run(string myQueueItem, TraceWriter log) {

       try
{

//MYDBcontext is being set in application settings on azurefunctions with the connectionstring as value log.Info(GetConnectionStringVariable(“MYDBContext”)); } catch (System.Exception ex) { log.Info($“Error Occured : {ex}”); throw ex; }

}

public static string GetConnectionStringVariable(string name) {

return ConfigurationManager.ConnectionStrings[name].ConnectionString;

}

and in the shared folder place these two dlls EntityFramework.dll EntityFramework.SqlServer.dll

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to load Entity Framework Core into C# azure function
Private.CoreLib: Exception while executing function: Function1. FunctionApp1: Could not load file or assembly 'Microsoft.EntityFrameworkCore, ...
Read more >
Troubleshoot error: Azure Functions Runtime is unreachable
This issue occurs when the Functions runtime can't start. The most common reason for this is that the function app has lost access...
Read more >
Guide for running C# Azure Functions in an isolated worker ...
Learn how to use a .NET isolated worker process to run your C# functions in Azure, which supports non-LTS versions of .NET and...
Read more >
Handling errors in Durable Functions (Azure Functions)
Any exception that is thrown in an activity function is marshaled back to the orchestrator function and thrown as a FunctionFailedException .
Read more >
Durable entities - Azure Functions
Learn what durable entities are and how to use them in the Durable Functions extension for Azure Functions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found