0

I've got a Visual Studio solution that I'm trying to test a deploy for. The solution has multiple projects in it and references a bunch of different components from the .Net framework and elsewhere. All of my components are in C#, except one which is in VB.Net (will get upgraded at some point, but needs to be done in one shot and is large).

The project structure is:

enter image description here

Everything works well on my dev machine. However, when I deploy to a test machine, which is Windows 10 + updates, and purposely no internet connection (a valid test), I get an issue when running part of the program within the Dolphin component.

The code erroring on the test machine is:

oValue = New SqlGeometry() <-- this does not error
oValue.Parse("LINESTRING (100 100, 20 180, 180 180)") <--- this errors

The error is:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

I'm looking to use SqlGeometry and SqlGeography in AppData and AppBuilder. I have both SqlServerSpatial110.dll and Microsoft.SqlServer.Types.dll in the same folder as the EXE and DLLs.

If I try and add a references within Dolphin (VB.Net) to SqlServerSpatial110.dll, I get the following error message indicating that this cannot be done:

enter image description here

If I try and manually register SqlServerSpatial110.dll on the test machine from within the target app directory using regsvr32, I get the error:

The module 'SqlServerSpatial110.dll' failed to load.

Make sure the binary is stored at the specified path or debug it to check for problems with the binary of dependent .DLL files.

The specified module could not be found.

SqlServerSpatial110.dll is in the System32 directory on my dev machine, but not on the test machine. My experience level in writing manifest files is none at all, and I'm hoping to keep it that way. For reference I'm using a deployment product called DeployMaster, but that is fairly irrelevant to the question. All components are set to x86 compilation. It's a winforms app

In short, how do I reference SqlServerSpatial110.dll from Dolphin to get it deployed and used correctly?

Mark Roworth
  • 409
  • 2
  • 15
  • 1
    Does this answer your question? [System.DllNotFoundException: Unable to load DLL 'SqlServerSpatial110.dll': The specified module could not be found](https://stackoverflow.com/questions/28240474/system-dllnotfoundexception-unable-to-load-dll-sqlserverspatial110-dll-the-s) – GSerg Oct 11 '21 at 12:10
  • Does this answer your question? [Unable to load SqlServerSpatial.dll](https://stackoverflow.com/q/14265845/11683) – GSerg Oct 11 '21 at 12:11
  • @GSerg - I have previously read both of those links and am unsure how to apply them to the deployment of a winforms app. The first link relates to a web.config file and nuget, neither of which I am using, and the second link relates to WCF on an IIS server. The first looks more promising, but I'm not expecting an end user to use nuget, which this solution implies. – Mark Roworth Oct 11 '21 at 12:19
  • You are supposed to redistribute your libraries correctly. Either your setup project must set them up, or the user must install them separately, https://stackoverflow.com/q/29143630/11683 – GSerg Oct 11 '21 at 12:24
  • Hi @GSerg, yes, I understand that, and I'm hoping to do it by setting the solution up correctly, hence my original question, "how do I reference SqlServerSpatial110.dll from Dolphin to get it deployed and used correctly?" I have done a fairly thorough search for other answers before posting. Thanks for any advice you can provide. It seems these two DLLs provide considerable problems for people with no clear solution. – Mark Roworth Oct 11 '21 at 12:42
  • The following may be helpful: https://stackoverflow.com/questions/16868326/unable-to-load-dll-sqlserverspatial-dll and https://www.microsoft.com/en-us/download/details.aspx?id=100451 – Tu deschizi eu inchid Oct 11 '21 at 12:58
  • @user9938 - thank you. I think this is helping me progress. I'd not previously realised that SqlServerSpatial.dll is unmanaged code and Microsoft.SqlServer.Types.dll is managed code that wraps (I think?) SqlServerSpatial.dll. I've added SqlServerSpatial.dll to Dolphin and set ```Copy To Output Directory = Copy Always```. Am getting a different error at the same place now, which is: ```An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)``` At least this is something else. Any ideas? Thanks. – Mark Roworth Oct 11 '21 at 14:58
  • 1
    An "incorrect format" error suggests that you may have 32-bit vs. 64-bit issues. – Craig Oct 12 '21 at 13:50

2 Answers2

0

I would not think this has much to do with c# vs VB.Net, once built there should only be .Net assemblies, and it should not matter what language that was used.

The correct solution should be to register a nuget dependency on Microsoft.SqlServer.Types for the project that needs this assembly. I.e. go to "Tools\Nuget Package Manager\Manage packages for solution" and install the package above in your dolphin project.

This should ensure that the needed dlls are downloaded from the internet and copied to your output directory, but you might need to include manually it if your are using any kind of installation framework.

JonasH
  • 28,608
  • 2
  • 10
  • 23
0

I've found a resolution to this. This is a solution for winforms. I've only seen solutions for Azure or WFC or asp.net online so hopefully this will act as a guide for others. It requires all the projects in the solution to be 64 bit, but for me that's no problem. The steps I've take are:

  • change all the projects to be x64
  • using nuget add Microsoft.SqlServer.Types to all projects in the solution that touch SQL spatial types.
  • in app.config, include the following:
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  • early on in the code, within the application, before any of the SQL spatial types are required, execute the following code (this is the code suggested by nuget at the bottom of the readme page shown after the package is installed):
using System.Reflection;
...
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
  • in your installation software, ensure that <yourexename>.exe.config is deployed to the %APPFOLDER% (the folder where your app is deployed to).
  • also, in %APPFOLDER% include the file: Microsoft.SqlServer.Types.dll
  • also, in %APPFOLDER% you need the following structure (which you should be able to copy from your project folder):
%APPFOLDER%\Microsoft.SqlServer.Types.dll (14.0.1016.290)
%APPFOLDER%\SqlServerTypes\x64\msvcr120.dll (12.0.40649.5)
%APPFOLDER%\SqlServerTypes\x64\SqlServerSpatial140.dll (14.0.1016.290)

However, I've additionally found that Visual Studio has issues with using UserControls from 64 bit class libraries. The symptom from this will be that the project builds without errors, but if you try to open a form with a 64 bit UserControl on it, it will show errors.

To resolve this use the configuration manager and set Debug configuration to be 32 bit and Release to 64 bit. Develop in Debug configuration and release in (uh) Release configuration.

If anyone adapts the resolution regarding the build and location of DLLs for 32 bit, it would be useful to me, so please do post it or a link to it below. Thanks.

Mark Roworth
  • 409
  • 2
  • 15