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

前端 未结 9 2335
谎友^
谎友^ 2021-02-12 13:05

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 particula

相关标签:
9条回答
  • 2021-02-12 13:24

    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.

    0 讨论(0)
  • 2021-02-12 13:28

    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.

    0 讨论(0)
  • 2021-02-12 13:28

    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

    0 讨论(0)
  • 2021-02-12 13:29

    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

    0 讨论(0)
  • 2021-02-12 13:37

    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.

    0 讨论(0)
  • 2021-02-12 13:43

    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

    0 讨论(0)
提交回复
热议问题