0

I have no idea why its trying to find v15.0 as I am explicitly trying to tell it to load v14.0. When adding NuGet package, the highest version I see is 14.x. This works perfectly on my dev machine, but when deployed to prod (win2019/sql server 2019 with CU8) I get the above error.

I only get error when I invoke GetPointFromLatLong

    static DbGeography GetPointFromLatLong(double lat, double lng)
    {
        return DbGeography.FromText(string.Format("POINT({0} {1})", lng, lat), 4326);
    }


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


namespace SqlServerTypes2
{
    /// <summary>
    /// Utility methods related to CLR Types for SQL Server 
    /// </summary>
    public class Utilities
    {
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr LoadLibrary(string libname);

        /// <summary>
        /// Loads the required native assemblies for the current architecture (x86 or x64)
        /// </summary>
        /// <param name="rootApplicationPath">
        /// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
        /// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
        /// </param>
        public static void LoadNativeAssemblies(string rootApplicationPath)
        {
            var nativeBinaryPath = IntPtr.Size > 4
                ? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
                : Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");

            LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll");
            LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll");
        }

        private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
        {
            var path = Path.Combine(nativeBinaryPath, assemblyName);
            var ptr = LoadLibrary(path);
            if (ptr == IntPtr.Zero)
            {
                throw new Exception(string.Format(
                    "Error loading {0} (ErrorCode: {1})",
                    assemblyName,
                    Marshal.GetLastWin32Error()));
            }
        }
    }
}
Zoinky
  • 4,083
  • 11
  • 40
  • 78

1 Answers1

0

I am guessing you don't have it installed on the server, since SqlServerSpatial.dll is unmanaged-code.

  1. Manually copy/install the correct version (64bit) on the server.
  2. Then add that DLL to your project.
  3. Lastly, select the dll in your references and Set the properties of SqlServerSpatial110.dll to “Copy to Output directory = Copy always”

Another option is copy it from the install directory as mentioned here, just make sure your version lines up

Transformer
  • 6,963
  • 2
  • 26
  • 52