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:
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:
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?
CodePudding user response:
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.
CodePudding user response:
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)
If anyone adapts this for 32 bit, it would be useful to me too if you'd be kind enough to post it below. Thanks.