Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Provider Manifest is incorrect #93

Closed
jdavi37 opened this issue Mar 4, 2022 · 15 comments
Closed

The Provider Manifest is incorrect #93

jdavi37 opened this issue Mar 4, 2022 · 15 comments

Comments

@jdavi37
Copy link

jdavi37 commented Mar 4, 2022

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:

using (var ctx = new MyCustomDbContext(_connectionString))
{
    var dbEntities = ctx.SomeEntity.Include("SomePath").ToList(); //this line errors    
...

Full Error
(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.
(167,10) : error 0122: The value 'HierarchyId' is not a valid PrimitiveTypeKind.
Source = EntityFramework
StackTrace = at System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest.Load(XmlReader reader)
at System.Data.Entity.SqlServer.SqlProviderManifest..ctor(String manifestToken) in //src/ErikEJ.EntityFramework.SqlServer/SqlProviderManifest.cs:line 62
at System.Data.Entity.SqlServer.MicrosoftSqlProviderServices.<>c.b__29_0(String s) in /
/src/ErikEJ.EntityFramework.SqlServer/MicrosoftSqlProviderServices.cs:line 482
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken)
at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.Include(String path) at System.Data.Entity.Infrastructure.DbQuery1.Include(String path)

Thanks for your time.

@CZEMacLeod
Copy link

@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.

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 6, 2022

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.

@jdavi37
Copy link
Author

jdavi37 commented Mar 8, 2022

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:
image

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 9, 2022

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)

https://github.com/dotnet/ef6/blob/main/src/EntityFramework/Resources/System/Data/System.Data.Resources.ProviderServices.ProviderManifest.xsd#L122

Maybe @bricelam or @ajcvickers has some clue?

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 9, 2022

@jdavi37 You can share something and let me know via email: ejlskov at hotmail dot com

@jdavi37
Copy link
Author

jdavi37 commented Mar 9, 2022

Sent the repro project and some details over to you.

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 9, 2022

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)

@jdavi37
Copy link
Author

jdavi37 commented Mar 9, 2022

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
image

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
image

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 9, 2022

@jdavi37 I honestly have no idea...

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 9, 2022

Oddly enough I see the same error in VS 2022 XML editor:

image

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 9, 2022

Just a thought: is EntityFramework.dll in GAC?

You can run

gacutil /l > gaclist.txt

and look at the result

@jdavi37
Copy link
Author

jdavi37 commented Mar 10, 2022

It is not in the GAC, according to that command.

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 10, 2022

I have run out of good ideas atm

@jdavi37
Copy link
Author

jdavi37 commented Mar 10, 2022

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!

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 10, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants