Microsoft.SqlServer.Types incompatible with .NET Standard
Asked Answered
A

1

12

I'm attempting to convert all of our C# class libraries from .NET Framework to .NET Standard projects, as we are starting to leverage .NET Core so need these to be consumable by both .NET Core and .NET Framework apps (with the latter being ported over to Core in the upcoming months.)

I'm having trouble converting our data access layer code because we leverage Microsoft.SqlServer.Types extensively and the official NuGet package doesn't support .NET Standard. I tried an unofficial NuGet package by dotmorten but it's missing a lot of functionality. Below is a list of everything missing that we would need (thrown together to get the code building...)

public static class SqlMockExtensions
{
    public static SqlBytes STAsBinary(this SqlGeography geography) => throw new NotImplementedException();

    public static SqlGeography MakeValid(this SqlGeography geography) => throw new NotImplementedException();

    public static int STDimension(this SqlGeography geography) => throw new NotImplementedException();

    public static bool STIsValid(this SqlGeography geography) => throw new NotImplementedException();

    public static Nullable<double> EnvelopeAngle(this SqlGeography geography) => throw new NotImplementedException();

    public static SqlGeography ReorientObject(this SqlGeography geography) => throw new NotImplementedException();

    public static SqlGeography BufferWithTolerance(this SqlGeography geography, double arg1, int arg2, bool arg3) => throw new NotImplementedException();

    public static SqlGeography Reduce(this SqlGeography geography, double tolerance) => throw new NotImplementedException();

    public static SqlGeography EnvelopeCenter(this SqlGeography geography) => throw new NotImplementedException();

    public static double STDistance(this SqlGeography geography, SqlGeography point2) => throw new NotImplementedException();

    public static SqlBytes STAsBinary(this SqlGeometry geometry) => throw new NotImplementedException();
}

When I search SO for others trying to integrate Microsoft.SqlServer.Types into their .NET Core and Standard projects, I see mentions of including the official NuGet package and then doing something like this:

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

However, it errors when you try to add a non-.NET Standard compliant NuGet package into a .NET Standard project, so I'm not clear how this is a solution.

This seems like a very common problem to have, there have to be a lot of developers out there who leverage Microsoft.SqlServer.Types for SqlGeography, SqlGeometry, etc... and are porting over to .NET Standard. So how are all of you accomplishing this?

Aguedaaguero answered 30/1, 2019 at 19:28 Comment(5)
Same problem... not sure if you are following this github.com/dotnet/corefx/issues/31775Paramagnetism
Does dotMorten.Microsoft.SqlServer.Types not work for you?Banded
How did you solve this? I am stuck migrating some of my applications to .NET Standard because of this issuePascia
@RobL I ended up just referencing the DLL's directly (browse and add them as normal references) instead of using nuget packages. This obviously won't work in .NET Standard on a non-Windows platform.Aguedaaguero
@Aguedaaguero what if you conditioned your <Reference tags with a platform check condition, effectively manually creating what nuget does for you when you add a reference.Victoir
H
2

For what it's worth, we did not find an answer.

We ended up moving to EF Core.

Hedve answered 25/7, 2021 at 13:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.