c# - 无法加载 DLL 'SqlServerSpatial150.dll':找不到指定的模块。(仅在产品上)
问题描述
我不知道为什么它试图找到 v15.0,因为我明确地试图告诉它加载 v14.0。添加NuGet包时,我看到的最高版本是14.x。这在我的开发机器上完美运行,但是当部署到 prod(带有 CU8 的 win2019/sql server 2019)时,出现上述错误。
我只在调用时收到错误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()));
}
}
}
}
解决方案
推荐阅读
- android - supportFragmentManager 变量在哪里定义?
- git - 有没有办法在不克隆的情况下查找远程 Git 服务器上是否存在提交/sha
- spring-batch - 多作业 Spring Batch 应用程序可以加载最少的 bean 集吗?
- html - 有什么方法可以对齐徽标,使它们都位于同一基线上?
- apache-nifi - 为什么NIFI不能用REGISTRY启动版本控制?
- itext7 - 如何将 CPS 链接信息添加到法律声明选项卡?
- python - 如何在 Tkinter 中创建字体轮廓
- node.js - 如何防止恶意软件上传以保存网络公共图像?
- laravel - 跨域请求被阻止 Laravel
- excel - 在 Angular 中使用 xlsx - 如何让 excel 自动将日期识别为列中的实际日期?