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

.NET Core 3.1 and SQL Server hierarchyid - multiple exceptions #18

Closed
alvipeo opened this issue Aug 17, 2020 · 2 comments
Closed

.NET Core 3.1 and SQL Server hierarchyid - multiple exceptions #18

alvipeo opened this issue Aug 17, 2020 · 2 comments

Comments

@alvipeo
Copy link

alvipeo commented Aug 17, 2020

Please see this - https://stackoverflow.com/q/63430419/2896495.

@bkarakaya01
Copy link

The exception throwed while using Microsoft.SqlServer.Types is a dll error, and base on this issue, you can resolve the assembly which cannot be resolved like below,

Also please see this discussion in dotMorten's Microsoft.SqlServer.Types issue.

AssemblyLoadContext.Default.Resolving += OnAssemblyResolve;

Assembly OnAssemblyResolve(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName)
{
  try
  {
    AssemblyLoadContext.Default.Resolving -= OnAssemblyResolve;
    return assemblyLoadContext.LoadFromAssemblyName(assemblyName);
  }
  catch
  {
    if (assemblyName.Name == "Microsoft.SqlServer.Types")
      return typeof(SqlHierarchyId).Assembly;
    throw;
  }
  finally
  {
    AssemblyLoadContext.Default.Resolving += OnAssemblyResolve;
  }
}

For Binary Serialization Exception:

Again in dotMorten package issues 1 and 2,, there is a discussion about serializing manually,

var binvalue = reader.GetSqlBytes(rowid);
var g = SqlGeometry.Deserialize(binvalue);

As EntityFrameworkCore.SqlServer.HierarchyId description, it says : "Adds hierarchyid support to the SQL Server EF Core provider." for this package, so I don't really know about using this without EFCore, but I am using .NET Core version=3.1 in my project and EntityFrameworkCore.SqlServer.HierarchyId version=1.1.0,

and my csproj configurations are:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="Concrete\PortalManual\" />
    <Folder Include="Concrete\ServiceBulletin\" />
    <Folder Include="Concrete\Warranty\" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="EntityFrameworkCore.SqlServer.HierarchyId" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.6" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
  </ItemGroup>

</Project>

The main difference that I can see is that I am using System.Data.SqlClient except Microsoft.Data.SqlClient

@alvipeo
Copy link
Author

alvipeo commented Aug 21, 2020

Thank you!

@alvipeo alvipeo closed this as completed Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants