NickStrupat / EntityFramework.Triggers

Adds events for entity inserting, inserted, updating, updated, deleting, and deleted
MIT License
373 stars 46 forks source link

EF Core 2.0.2 Add-Migration Problems #32

Closed jensschmidbauer closed 6 years ago

jensschmidbauer commented 6 years ago

Hi there,

I'm currently setting up a new project with Entity Framework Core 2.0.2 (target framework is net461 and platform x64) and tried to install EntityFramework.Triggers, but I have two problems getting the Add-Migration command to work again (like it did before I installed the package).

The first try was only installing the package and inheriting from DbContextWithTriggers. The result was Add-Migration did not recognize my DbContext any more ("No DbContext named '...' was found"). Is this quite normal?

So, next try was with the alternative way of overwriting SaveChanges-Methods. This time Add-Migration worked as before. But there's no trigger defined yet. Next step was to add a test trigger in my user entity:

static User
{
    Triggers<User>.Inserted += o => {};
}

and run Add-Migration again, resulting in a FileLoadException on trying to load "Microsoft.EntityFrameworkCore, Version 2.0.0.0" (instead of 2.0.2.0 which is used everywhere)

System.TypeInitializationException: Der Typeninitialisierer für "EntityModel.User" hat eine Ausnahme verursacht. ---> System.IO.FileLoadException: Die Datei oder Assembly "Microsoft.EntityFrameworkCore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040) bei EntityModel.User..cctor()

and the exceptions's FusionLog property states it's called by "EntityFrameworkCore.Triggers, Version=1.1.1.0":

I can't any reference to version 2.0.0.0 anywhere und don't have any further ideas how to solve this for the moment. Hope you can help me.

jensschmidbauer commented 6 years ago

Hi again,

found the problem (solved both things).

My entity model is defined in a separate assembly and Add-Migration somehow uses that assembly as StartupProject - which strangely enough seems to have worked before (until I started to use triggers). So specifying the -StartupProject parameter with the correct project made both variants work.

Thanks for reading, sorry for bothering, problem solved.