Unable to load DLL 'SqlServerSpatial140.dll': The specified module could not be found

给你一囗甜甜゛ 提交于 2021-01-20 23:41:31

问题


This all new to me, so bear with me...

I'm working on a Visual Studio project; it's a web service that returns some data.

I've just tried to make a particular call to the web server on my local machine (IIS) and I'm getting this error:

Unable to load DLL 'SqlServerSpatial140.dll': The specified module could not be found

Before anyone says it - yes, obviously I am missing this DLL file. I've searched online and don't see where I could download it from (I have Microsoft SQL Server System CLR Types (x64) and non-X64 both installed. I have Microsoft System CLR Types for SQL Server 2014 and 2016 both installed)

Does anyone know how to fix this? Does anyone know if I can just download this file from somewhere?


回答1:


Copy the dll from C:\Users\<User>\.nuget\packages\Microsoft.SqlServer.Types\14.0.314.76\nativeBinaries\x86 to your project. Right-click the file and click Properties. Set "Copy To Output Directory" to "Copy Always".




回答2:


For those who are seeing a very similar set of errors, something like:

Could not copy the file "…\SqlServerTypes\x64\SqlServerSpatial140.dll" because it was not found

If you installed Microsoft.SqlServer.Types via NuGet and your application works locally but you get errors when building via Azure DevOps then you simply need to add the dlls to source control. As @Pure.Krome noted, these dlls exist locally at:

However, notice that by default these dlls are ignored (red icon at left). Right-click the ignored dlls and select Add Ignored File to Source Control… then commit and push your changes, then queue a new build! Note: Your solution may contain several projects, and each may have their own SqlServerTypes folder.




回答3:


When you install the Microsoft.SqlServer.Types nuget package, this should create a new folder in root:

\SqlServerTypes
   |_x64
   |_x86

which should contain the appropriate dll's. It's also auto setup to copy if newer.

Then, make sure your app loads the appropriate assembly:

  • For ASP.NET Web Applications: SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
  • For desktop applications / others: SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

Not sure if this works with .NET Core though.




回答4:


My problem was git related: a fresh clone of solution (kept on TFS) seemed to be broken, although my fellow developers had no problem. In my case "resetting" did the trick:

  • uninstall nuget Microsoft.SqlServer.Types 14.0.314.76
  • clear / rebuild project
  • install nuget Microsoft.SqlServer.Types 14.0.314.76
  • clear / rebuild project



回答5:


Thank you very much. It worked for me very well. I lost a lot of time on this, but you saved me! :)

I added this to my Global.asax.cs =>

 `protected void Application_Start()
    {
     SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));`

And then in my Solution Explorer => toggled show all file and Add Ignored File to Source Control… as Pure.Krone said.




回答6:


I fixed this by issuing the following command in the Package Manager Console:

Update-Package -Reinstall Microsoft.SqlServer.Types

The output included some dire-looking warnings and errors, but in the end it indicated that the package was successfully installed. And the build errors vanished.




回答7:


I had this problem but I found a solution for it. I had some new entities with the System.Data.Entity.Spatial.DbGeometry type and I kept getting the System.DllNotFoundException: Unable to load DLL 'SqlServerSpatial140.dll' when I ran the Add-Migration command. I had installed the SqlServerTypes library from nuget, which placed a folder in my solution like @mattavatar's post illustrated, but I was still getting the exception.

What fixed it for me was copying these DLLs to C:\Windows\SysWOW64. This is dependent on the architecture of your machine, and your IIS configuration. For my I am running on a 64 bit machine, but IIS is configured to run 32 bit apps. In this case, I had to copy the 32 bit dll to C:\Windows\SysWOW64. If you're running a 32 bit machine, you'll want to copy the 32 bit dll to C:\Windows\System32. If you copy a 64 bit dll where it is expecting a 32 bit one, and you run the Add-Migration command, you'll get the System.BadImageFormatException.

Hopefully this helps someone. I spent want too long trying to figure this out. Credit to @pflous' comment https://stackoverflow.com/a/39009634/6697928




回答8:


What worked for me was to go to this file location below and copy the SqlServerSpatial240.dll to my project bin folder.

C:\Users<user>.nuget\packages\microsoft.sqlserver.types\14.0.1016.290\nativeBinaries\x64




回答9:


I had a similar problem and my files from the sub-folder \SqlServerTypes (installed as @Pure.Krome described) where missing/discarded by my settings in NuGet.Config. I had to uninstall and reinstall the Nuget package Microsoft.SqlServer.Types



来源:https://stackoverflow.com/questions/42654893/unable-to-load-dll-sqlserverspatial140-dll-the-specified-module-could-not-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!