Closed jdavi37 closed 2 years ago
@jdavi37 To use HierarchyId or the spatial you need to load the sql server types from a custom assembly. Not sure exactly how this works for Microsoft.Data.SqlClient, but I'm guessing you need startup code similar to
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
System.Data.Entity.SqlServer.MicrosoftSqlProviderServices.SqlServerTypesAssemblyName = typeof(SqlGeography).Assembly.FullName;
Note that I have changed the 'normal' System.Data.Entity.SqlServer.SqlProviderServices
to System.Data.Entity.SqlServer.MicrosoftSqlProviderServices
so that the new provider is set.
Haven't tried this myself (yet) but I may need to in the future as I too am looking to migrate to MDS and use HierarchyIds in my code.
I was not able to repro after following the guide for mapping here: https://softwarehut.com/blog/tech/hierarchyid-entity-framework - in a .NET Framework project with Code First from Database.
We aren't actually using the 'HierarchyId' type anywhere in the project. I have a super simple repro project that I can share (the zip is 84 MB unfortunately, so github won't let me attach it here). The DB has only one table with only one property, an int ID. For most of our developers, this project runs fine. For just a few, they run into the error above. Is there some part of this that is reliant on certain versions of SQL Server or some other obscure dependency that we could check to see if these environments are missing?
EDIT: On one of the affected developer machines, I cloned down the repo and opened the Solution "ErikEJ.EntityFramewrok.SqlServer" in vs 2019. When I open up the "System.Data.Resources.sqlClient.SqlProviderServices.ProviderManifest.xml" file in VS, I see the error here as well:
Do not understand why this validation error occurs, would like to get a repro project (and information about the SQL Server edition/version in use for the afftected developers)
Maybe @bricelam or @ajcvickers has some clue?
@jdavi37 You can share something and let me know via email: ejlskov at hotmail dot com
Sent the repro project and some details over to you.
Thanks for the repor project, unable to repro on my PC.
For the affected PCs:
Which exact VS version? Which OS version? Which SQL Server version do they access?
Do they have: "Microsoft SQL Server System CLR Types" installed? (check in Add/Remove)
Affected PCs: machine 1 Visual Studio Professional 2019 16.4.2 Windows 10 Enterprise 10.0.18362 SQL Server 2014 12.0.5000.0 has "Microsoft System CLR Types for SQL Server 2014" installed
machine 2 Visual Studio Enterprise 2019 16.11.9 Windows Server 2019 Datacenter, version 1809, OS build 17763.2452 SQL Server 2019 15.0.4.188.2 has "Microsoft System CLR Types for SQL Server 2019 CTP2.2" installed
machine 3 Visual Studio Enterprise 2017 15.9.36 Windows Server 2021 R2 SQL Server 2014 12.0.5000.0 has a number of CLR types for SQL Server installed
machine 4 Visual Studio Enterprise 2015 (14.0.23107.178), 2017 (15.9.28307.1064) & 2019 (16.6.30204.135) Windows Server 2019 Standard version 2809 17763.2452 SQL Server 2016 14.0.3430.2 Also has a number of CLR Types for SQL Server installed
@jdavi37 I honestly have no idea...
Oddly enough I see the same error in VS 2022 XML editor:
Just a thought: is EntityFramework.dll in GAC?
You can run
gacutil /l > gaclist.txt
and look at the result
It is not in the GAC, according to that command.
I have run out of good ideas atm
So I checked again (not sure how I missed it the first time) and we did have EF 6 dlls in the GAC on these machines, and removing them resolves the issue. Thanks so much!
Hooray!!
And thanks for your patience and help. This is also very valuable for future usage of this library, I will add this info to the docs.
Hello!
My team is working on a project which uses Entity Framework 6.4. However due to project requirements we need to migrate to using Microsoft.Data.SqlClient, and so we are using your NuGet package. We removed references to EntityFramework, installed your nuget package, updated our custom DbContext with the DBConfigurationType attribute
[DbConfigurationType(typeof(System.Data.Entity.SqlServer.MicrosoftSqlDbConfiguration))]
as you mentioned in the readme, and updated all references to System.Data.SqlClient to the new Microsoft.Data.SqlClient.Some of our team members run into this "Provider Manifest/PrimitiveTypeKind" error at runtime when the dbcontext is used. Any ideas as to what might be causing this issue, or next steps to troubleshoot? It seems these environments are having an issue loading "System.Data.Resources.SqlClient.SqlProviderServices.ProviderManifest.xml."
The offending code looks like:
Full Error