Why adding a model Entity Framework to csproj fail?
Asked Answered
D

2

6

Here is my project file csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
     <TargetFramework>net4.6</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
     <PackageReference Include="EntityFramework" Version="6.2.0" />
  </ItemGroup>
</Project>

In VisualStudio 2017 I try to add item "ADO.NET Entity Data Model". When push the Add button VS throw me an exception...

Exception

In the log file I got this :

===================== 2018-02-21 15:23:47 Recoverable System.Reflection.TargetInvocationException: An exception was raised by the target of a call. ---> Microsoft.VisualStudio.ProjectSystem.ProjectException: The item type 'EntityDeploy' is not supported by this project item provider. at Microsoft.VisualStudio.ProjectSystem.ProjectErrorUtilities.ThrowProjectExceptionHelper(Exception innerException, String unformattedMessage, Object[] args) at Microsoft.VisualStudio.ProjectSystem.ProjectErrorUtilities.ThrowProjectException(String message, Object arg0) à Microsoft.VisualStudio.ProjectSystem.CpsProjectItem`1.d__25.MoveNext()

Dodecasyllable answered 21/2, 2018 at 20:55 Comment(1)
This is not exact solution for this might help: #44299832Zorazorah
D
7

This issue describes the same exception as your log contains:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.VisualStudio.ProjectSystem.ProjectException: The item type 'EntityDeploy' is not supported by this project item provider.

Unfortunatelly it does not have a direct solution.

Overall you shouldn't expect smooth functioning of EF tools with new csproj format. There is a discussion in EntityFramework6 repository which collects some of the known issues, both for migrations and EF tools. There is an explicit statement of EF team that we shouldn't expect near fixes for these problems:

On the flips side, working with EF6 in an ASP.NET Core application is possible but requires workarounds. E.g. in this case, keep the model in a separate .NET Framework library with a traditional project file, and unload any projects from the solution that use the new project system while working with migrations.

We are reluctant to commit to making EF6 migrations fully work with the new project system because we believe that would involve a significant investment which would hinder our progress on our main strategy, but perhaps there are less expensive things we can do to reduce the friction of the workarounds, e.g. make it so that you still need to put the EF6 model in a separate project but at least you don't need to unload other projects.

Regarding your problem I could suggest the following:

  1. Try updating to the latest Visual Studio version. I'm working with VS 2017 version 15.3.0 and I don't have the same issue as you get. I still get spontaneous error/warning messages during model generation and working with designer, however the model is generated correctly eventually.

  2. If it will not work for you, consider switching to the workaround suggested by EF team, i.e. keeping EF model in a separate library project with a traditional project file.

Well, such suggestions might not suit the perfectionists, but (again) new csproj format is not yet fully adopted by all existing VS tools and it's unknown for this moment when it happen.

Dardani answered 22/3, 2018 at 5:44 Comment(1)
Hello, has this been fixed? I'm still getting the exact the same error. As for the workaround, can someone please explain what a traditional project file means? I've put the EF model in a separate folder, also tried unloading the project. Someone also suggested filling the configsection in the app.config that apparently do not get generated manually anymore. Plz someone help :/Nitza
M
0

EF6 6.4.x now supports Microsoft.Net.SDK style projects.

You should note that EF6 is still not aware of AutoGenerateBindingRedirects flag.

When you run

Add-Migrations Add_Customer_Table

and if you get "System.IO.FileLoadException" then you should add the binding redirects into the app.config manually

Myer answered 5/7, 2021 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.