SqlClient: Edmx and Microsoft.Data.SqlClient result in HierarchyId invalid error

Describe the bug

In order to integrate the model first edmx entity framework 6 experience with Microsoft.Data.SqlClient we changed the value of the Provider attribute on the Schema element to Microsoft.Data.SqlClient. As per the instructions on https://github.com/ErikEJ/EntityFramework6PowerTools/blob/community/src/ErikEJ.EntityFramework.SqlServer/readme.md

But now the designer reports the following error:

<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    

Tested with .NET Framework 4.8. Package version 5.1.1.

This error isn’t blocking the designer, but whenever we do any database operations through the user experience, this error is blocking the process.

To reproduce

You can clone the following solution: https://github.com/cveld/sqlclient-hierarchyid-edmx-designer-error Open up the solution file in Visual Studio and then double click the edmx file in order to kick off the designer. You will see the reported error message in the error list dialog.

Expected behavior

The error shouldn’t be present and the database features should be working as designed.

Further technical details

Microsoft.Data.SqlClient version: 5.1.1 .NET target: Framework 4.8 SQL Server version: Azure Sql Database Operating system: Windows 11 Visual Studio: 17.5.4

Additional information

We initially reported the issue to https://github.com/ErikEJ/EntityFramework6PowerTools/issues/124 but @erikej does not have any visibility or responsibility towards the Visual Studio side of things.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (12 by maintainers)

Most upvoted comments

Create a simple repro console app and upload as .zip or github repo. Maybe you will learn something in the process 😉

@cveld

Windows 10E Version 21H2 Build 19044.2846 Visual Studio 2019 Enterprise 16.11.26 .NET Framework 4.8.09037 EntityFramework 6.4.4 ErikEJ.EntityFramework.SqlServer 6.6.5 Microsoft.Data.SqlClient 5.1.1

*You will need to modify the pathing/insertion points as needed for VS2017 and your subscription level.

  1. Close all VS instances.

  2. Launch CLI with elevated permissions and do the following:

cd C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE
:: dlls are 6.2.0.  Disassembly reveals that the embedded ProviderManifest xsd does not support the HierarchyId datatype. 
rename EntityFramework.dll EntityFramework.dll.og
rename EntityFramework.SqlServer.dll EntityFramework.SqlServer.dll.og
copy "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll"
copy "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll"
:: copy Microsoft.Data.SqlClient.dll from your project's packages\Microsoft.Data.SqlClient.5.1.1\lib\net462\ folder to the current folder
  1. Launch an editor with elevated permissions, e.g. Notepad++, and do the following:

    • Open C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Xml\Schemas\System.Data.Resources.ProviderServices.ProviderManifest.xsd
    • Insert the following at line 125 (under <xs:simpleType name=“TPrimitiveTypeKind”><xs:restriction base=“xs:string”>): <xs:enumeration value="HierarchyId" />
    • Save and then close the editor unless performing the next set of steps.
  2. (Optional) Prior to these steps, we were seeing this error when opening the EDM Designer and when rebuilding the solution: “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.” Curious that you are not. Using your editor, do the following:

    • Open C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe.config
    • Insert the following at line 1397 (under <system.data><DbProviderFactories>): <remove invariant="Microsoft.Data.SqlClient" /> <add name="SqlClient Data Provider" invariant="Microsoft.Data.SqlClient" description=".NET Framework Data Provider for SqlServer" type="Microsoft.Data.SqlClient.SqlClientFactory, Microsoft.Data.SqlClient" />
    • Save
  3. Open your solution in VS. Rebuild all. Open an edmx file.

Please tell us about your experience including any deviations or anomalies. If this solves your issue, please re-post the revised solution to Issue 10347962.