Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.SqlServer.Types in ASP NET Core

I'm trying to get the nuget package Microsoft.SqlServer.Types to work in ASP Core targeting full framework 461. I need to use the types SqlGeography and SqlHierarchyId. But when I run my test I get following error 'Unable to load DLL SqlServerSpatial140.dll'. I know when the package is installed the dlls file can be found in the .nuget\packages\microsoft.sqlserver.types\14.0.314.76\nativeBinaries\ folder.

But how do I include the dlls in my solution the best way?

I would like the dlls to be updated when the package is updated. The path can not be hardcode to a specific user path, it has to work on every pc setup.

like image 829
Michael Simonsen Avatar asked Aug 08 '17 08:08

Michael Simonsen


People also ask

Where is Microsoft SQL Server types DLL?

SqlServer. Types. dll from its location in C:\Windows\assembly\GAC_MSIL.

What is included in Microsoft SQL Server?

SQL Server services, tools and editions Also bundled with the DBMS are two sets of tools for DBAs and developers: SQL Server Data Tools, for use in developing databases, and SQL Server Management Studio, for use in deploying, monitoring and managing databases.

What database does .NET core use?

SQL Server is the most popular database when talking about ASP.NET Core since it's what Microsoft is also selling and also the first one that Entity Framework Core is developed for.


1 Answers

There is a readme.htm file included with the Microsoft.SqlServer.Types Nuget package. It will explain how to load the needed native dll files. Basically you need to call this line in your code:

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
like image 89
Vladimir Avatar answered Oct 17 '22 03:10

Vladimir