3

I'm using VS 2012 (Ultimate) together with Entity Framework Power Tools Beta 2 and entity framework 5.0 (using nuget).

I've created a DbContext class. When I right-click on the corresponding file in the solution explorer and select "Entity Framework / View Entity Data Model (Read-only)", I get the error "A constructible type deriving from DbContext could not be found in the selected file." error in VS 2012.

I tried the workaround described at http://blogs.msdn.com/b/adonet/archive/2012/04/09/ef-power-tools-beta-2-available.aspx, but my registry does not contain the key "{BFC24BF4-B994-4757-BCDC-1D5D2768BF29}" in "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\BindingPaths\".

After restarting visual studio and following the same steps, a dialog pops up indicating "Exception has been thrown by the target of an invocation".

BTW. I'm able to execute my test application that creates the database from my DbContext and O can insert/delete/etc data in this database.

Any help/hints would be very appreciated.

Kind regards, Merijn

Merijn
  • 661
  • 1
  • 7
  • 21

4 Answers4

4

Uninstalling VSCommands for Visual Studio 2012 should get things working again. Unfortunately, this extension does not play nicely with the EF Power Tools. It loads it's own version of EntityFramework.dll into the main VS process which prevents the DbContext discovery logic from working properly.

bricelam
  • 28,825
  • 9
  • 92
  • 117
  • Hi Brice, I work on VSCommands and wasn't aware of this issue before. I will try to get it fixed shortly. Do you have any hints on how different versions of EntityFramework.dll can be loaded in the same process or is such scenario not supported / recommended? – Jarek Kardas Jan 22 '13 at 17:02
  • 1
    @JarekKardas the VS Unit Test team had this issue in the VS 11 Developer Preview. I think they solved it either using an AppDomain or by loading the assembly into the load-from context. The API affected is VS's [DynamicTypeService](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.design.dynamictypeservice.aspx). Feel free to [reach out to us](http://blogs.msdn.com/b/adonet/contact.aspx) (the EF Team); we may be able to pull someone in from their team to provide more guidance. – bricelam Jan 22 '13 at 21:29
  • Got an email back and implemented fix in latest version of VSCommands, thank you for help Brice! – Jarek Kardas Jan 30 '13 at 07:46
  • Brice, I had this problem the other day after installing 2 extensions "HTML Spell Checker" and "Multi Language Spell Checker". I disabled HTML spell checker and the problem went away. I should check to see if enabling it again but disabling the other also works. Is it the extension or something about *installing* an extension? Blogged about it an some other designer issues here http://juliel.me/10BP7mf – Julie Lerman May 28 '13 at 13:45
  • @JulieLerman, The problem is typically with the extensions themselves. Extensions get loaded into the main VS AppDomain, and they need to be very careful not to do anything that would affect assembly resolution for other extensions. – bricelam May 28 '13 at 18:19
  • Git Extensions is another one that seems to have this problem. – Nathan Nov 07 '13 at 17:47
  • i am using visual studio 2013 and entity framework power tools Beta 4. I dont have VSCommand 2013 installed. But it gives me "A constructible type deriving from DbContext could not be found"...(Basically i need to add the edmx to add stored procedures function import) – Samra Mar 02 '17 at 05:23
3

As mentioned by Brice, this may be caused by compatibility issue with Visual Studio Extensions. Latest version of VSCommands fixes this problem. You can get if from Visual Studio Gallery.

Many thanks to Brice and EF Team for their help in diagnosing the problem!

Jarek Kardas
  • 8,445
  • 1
  • 31
  • 32
0

Having seen this error intermittently even without the extensions listed in the other answers, I found deleting the solution's local .suo file worked - although this was very much a when-all-else-fails answer!

Julia Hayward
  • 1,987
  • 1
  • 14
  • 16
0

I had a similar issue with a different Visual Studio Extension. In my case it was Visual Studio Tools for Git (Version 1.0.0.0).

I just disabled the extension, restarted VS2012 and I was able to use generate the model from a code first EF project.

phufbq
  • 1