-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Could not load file or assembly Microsoft.SqlServer.Types #22
Comments
I'm hitting the same problem, EF Core 2.2.0 - it's got me stumped? |
You'd need to serialize it yourself. var binvalue = reader.GetSqlBytes(rowid);
var is = SqlHierchyId.Deserialize(binvalue); See the unit tests for examples. |
@dotMorten Thanks, that got me going. I was able to select the id as a string and then parse it, I don't think there is a Deserialize extension for SqlHierarchyId. private SqlHierarchyId GetHierarchyId(Guid id)
{
using (var command = db.Database.GetDbConnection().CreateCommand())
{
command.Parameters.Add(new SqlParameter("param", id));
command.CommandText = "select [HierarchyId].ToString() as 'hid' from MyTable where Id = @param";
db.Database.OpenConnection();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
if (!reader.IsDBNull(0))
return SqlHierarchyId.Parse(reader.GetString(0));
}
}
}
return SqlHierarchyId.Null;
} |
You can also fix it using custom assembly resolver. Check my answer here https://stackoverflow.com/a/57373622/1641529 |
@MaceWindu Your resolver can be simplified by returning private static Assembly Default_Resolving(AssemblyLoadContext context, AssemblyName requestedAssembly)
{
// SqlServer.Types assembly redirection
if (requestedAssembly.FullName == "Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91")
{
return typeof(Microsoft.SqlServer.Types.SqlHierarchyId).Assembly;
}
return null;
} From official doc AssemblyLoadContext.Resolving Event: "If more than one event handler is registered for this event, the event handlers are called in order until an event handler returns a value that isn't null." |
@dotMorten For a |
Thank you for your answers, but now I have a different error which is : Unable to cast object of type 'Microsoft.SqlServer.Types.SqlHierarchyId' to type 'Microsoft.Data.SqlClient.Server.IBinarySerialize'. I'm new, so I'll be so happy if you could help me. :) |
You are trying to use it with |
I thought, I was doing what you were saying... Entities.csproj Web.csproj |
You also need to change usings/namespaces in code to reference types from new provider |
I am using EF Core 2.2.4. One of the entities contains SqlHierarchyId property. When I perform write operations to the database - adding new entities - it works fine. When I perform read operation, I get the following exception:
My guess is when EF attempts to map records to entities containing sqlhierarchyid, it looks for a classic library instead of this one.
The text was updated successfully, but these errors were encountered: