azure-functions-core-tools: Registration of a type derived from DbContext throws "Violates the constraint of type parameter DbContext"
We have an asp.net core 2.2 web API which works perfectly. We decided to move to Azure Durable Functions and hence started using IFunctionsHostBuilder
to wire up the very same services. When running the application, the following exception is thrown.
[2019-05-25 6:04:29 PM] A host error has occurred [2019-05-25 6:04:29 PM] MyDurableFunctionApp.Function: GenericArguments[0], ‘MyDurableFunctionApp.Database.Context.AccountManagementDbContext’, on ‘MyDurableFunctionApp.Repository.DbContextTransaction`1[TDbContext]’ violates the constraint of type parameter ‘TDbContext’.
AccountManagementDbContext
is derived indirectly from DbContext
class defined in EF and TDbContext
is a generic type which expects DbContext
like the following code snippet:
public class DbContextTransaction<TDbContext> : IDisposable where TDbContext : DbContext
{
}
This is how the Azure Function’s defined:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
There are two nuget packages that may be important to consider which are:
- Microsoft.EntityFrameworkCore.Tools ver 2.2.4
- Microsoft.AspNetCore.Identity.EntityFrameworkCore ver 2.2.0
This issue is a 100% blocker and unfortunately, we had to drop pursuing the path of Azure Functions until hopefully the issue is resolved by Microsoft.
FYI: @miladghafoori
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 20 (1 by maintainers)
@benm-eras I left a note in Azure/azure-functions-host#4397 yesterday hoping for communicating the urgency of fixing this issue. Unfortunately, this issue has become a significant roadblock for us too. It will be great to hear from Microsoft’s relevant team’s folks on an ETA when this fix becomes available.
@jeffhollan @miladghafoori
Well, the reason for my concern is that there are a good number of other nuget packages (internal and Microsoft’s) that depend on each other. So, any downgrades in the two mentioned package may possibly cause downgrading in other packages and resulting in unforeseen situations. I will discuss it internally while waiting for the bug to be fixed which is preferred. /cc @miladghafoori
@jeffhollan There is a ReadMe file in the following repository that explains everything. Hope this repo helps you guys find out and address the root cause of the issue:
https://github.com/Arash-Sabet/DbContextRegistrationIssueAzureFunctionsv2/tree/master
FYI: @miladghafoori
Hard to say - can you provide a repro or at least give an example of how you are registering the services in the
FunctionsStartup