ErikEJ / EntityFramework6PowerTools

This is the codebase for Entity Framework 6 Power Tools Community Edition, and modern EF 6 providers for SQL Server and SQL Server Compact
Other
183 stars 27 forks source link

Edmx designer not working in Visual Studio 2022 #124

Closed cveld closed 1 year ago

cveld commented 1 year ago

The Edmx designer is not working in Visual Studio 2022 (version 17.4.2). We get the exception:

Severity Code Description Project File Line Suppression State Error Error 175: The ADO.NET provider with invariant name 'Microsoft.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details. ConsoleApp C:\work\git\ConsoleApp\Data\Model1.edmx 7

Any clue how to diagnose this further? Where is the inner exception logged? Is there a way to trigger the same exception through e.g. a tt file which also potentially runs in the same runtime context as the edmx designer?

At runtime the application runs perfectly.

I believe we have fully followed your guidance at https://github.com/ErikEJ/EntityFramework6PowerTools/blob/community/src/ErikEJ.EntityFramework.SqlServer/readme.md

We tried in a web.config world as well as a app.config world.

  1. edmx file schema provider changed to Microsoft.Data.SqlClient -- which resulted in this exception in the first place
  2. Added system.data DbProviderFactories section
  3. Added provider to entityFramework providers section ---> isn't this the only relevant line for the edmx designer to work without exceptions?
  4. Changed the provider inside the connectionstring.

Ad 2.

<system.data>
    <DbProviderFactories>
      <add name="SqlClient Data Provider" invariant="Microsoft.Data.SqlClient" description=".NET Framework Data Provider for SqlServer" type="Microsoft.Data.SqlClient.SqlClientFactory, Microsoft.Data.SqlClient" />
    </DbProviderFactories>
</system.data>

Ad 3.

  <entityFramework>
    <providers>
    <provider invariantName="Microsoft.Data.SqlClient" type="System.Data.Entity.SqlServer.MicrosoftSqlProviderServices, ErikEJ.EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

Tested with .NET Framework 4.8.

Packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Azure.Core" version="1.25.0" targetFramework="net48" />
  <package id="Azure.Identity" version="1.7.0" targetFramework="net48" />
  <package id="EntityFramework" version="6.4.4" targetFramework="net48" />
  <package id="ErikEJ.EntityFramework.SqlServer" version="6.6.5" targetFramework="net48" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.1" targetFramework="net48" />
  <package id="Microsoft.Data.SqlClient" version="5.1.1" targetFramework="net48" />
  <package id="Microsoft.Data.SqlClient.SNI" version="5.1.0" targetFramework="net48" />
  <package id="Microsoft.Identity.Client" version="4.47.2" targetFramework="net48" />
  <package id="Microsoft.Identity.Client.Extensions.Msal" version="2.19.3" targetFramework="net48" />
  <package id="Microsoft.IdentityModel.Abstractions" version="6.24.0" targetFramework="net48" />
  <package id="Microsoft.IdentityModel.JsonWebTokens" version="6.24.0" targetFramework="net48" />
  <package id="Microsoft.IdentityModel.Logging" version="6.24.0" targetFramework="net48" />
  <package id="Microsoft.IdentityModel.Protocols" version="6.24.0" targetFramework="net48" />
  <package id="Microsoft.IdentityModel.Protocols.OpenIdConnect" version="6.24.0" targetFramework="net48" />
  <package id="Microsoft.IdentityModel.Tokens" version="6.24.0" targetFramework="net48" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net48" />
  <package id="System.Configuration.ConfigurationManager" version="6.0.1" targetFramework="net48" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.6.0" targetFramework="net48" />
  <package id="System.IdentityModel.Tokens.Jwt" version="6.24.0" targetFramework="net48" />
  <package id="System.IO" version="4.3.0" targetFramework="net48" />
  <package id="System.Memory" version="4.5.4" targetFramework="net48" />
  <package id="System.Memory.Data" version="1.0.2" targetFramework="net48" />
  <package id="System.Net.Http" version="4.3.4" targetFramework="net48" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
  <package id="System.Runtime" version="4.3.0" targetFramework="net48" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net48" />
  <package id="System.Security.AccessControl" version="6.0.0" targetFramework="net48" />
  <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net48" />
  <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net48" />
  <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net48" />
  <package id="System.Security.Cryptography.ProtectedData" version="4.7.0" targetFramework="net48" />
  <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net48" />
  <package id="System.Security.Permissions" version="6.0.0" targetFramework="net48" />
  <package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net48" />
  <package id="System.Text.Encoding" version="4.3.0" targetFramework="net48" />
  <package id="System.Text.Encodings.Web" version="6.0.0" targetFramework="net48" />
  <package id="System.Text.Json" version="4.7.2" targetFramework="net48" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
</packages>
ErikEJ commented 1 year ago

You need VS 17.5 as should be noted in the latest readme

cveld commented 1 year ago

Great! Now I get some other errors:

<File Unknown>(167,34) : error 0005: The 'PrimitiveTypeKind' attribute is invalid - The value 'HierarchyId' is invalid according to its datatype 'http://schemas.microsoft.com/ado/2006/04/edm/providermanifest:TPrimitiveTypeKind' - The Enumeration constraint failed.

<File Unknown>(167,10) : error 0122: The value 'HierarchyId' is not a valid PrimitiveTypeKind.    ConsoleApp1    C:\work\git\ConsoleApp1\Model.edmx    7    
ErikEJ commented 1 year ago

Are these runtime or just designer errors? If runtime refer to the readme (again)

cveld commented 1 year ago

It is design time only. The designer is rendering, but we cannot execute a fresh import from database. In the latter, the errors are blocking.

ErikEJ commented 1 year ago

It is out of my hands... When the official provider appears, feel free to report an issue at https://github.com/dotnet/ef6tools

cveld commented 1 year ago

I see you reported the issue upstream at: https://github.com/dotnet/ef6tools/issues/42 You tried to fix it with https://github.com/dotnet/ef6tools/pull/43

Although I have some experience with xsd's I don't understand how I can patch my local stack to circumvent the error. Who is the consumer? Who is depending on C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Xml\Schemas\System.Data.Resources.ProviderServices.ProviderManifest.xsd.

Just adding the line <xs:enumeration value="HierarchyId" /> to it did not fix anything.

I am using version 4.1.1 of Microsoft.Data.SqlClient. Is the error caused by this package?

ErikEJ commented 1 year ago

You are using 5.1 / 5.1.1 if you use my package, but I think that it is unrelated

ErikEJ commented 1 year ago

@cveld Have you checked that EntityFramework is not in GAC?

cveld commented 1 year ago

Yes I saw the documented known issue and checked. But I couldn't find it in the GAC.