我有一個 Visual Studio 解決方案,我正在嘗試測驗部署。該解決方案中有多個專案,并參考了 .Net 框架和其他地方的一堆不同組件。我的所有組件都在 C# 中,除了在 VB.Net 中的一個(將在某個時候升級,但需要一次性完成并且很大)。
專案結構為:

在我的開發機器上一切正常。但是,當我部署到 Windows 10 更新的測驗機器并且故意沒有互聯網連接(有效測驗)時,在 Dolphin 組件中運行部分程式時出現問題。
測驗機上報錯的代碼是:
oValue = New SqlGeometry() <-- this does not error
oValue.Parse("LINESTRING (100 100, 20 180, 180 180)") <--- this errors
錯誤是:
試圖加載格式不正確的程式。(來自 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?
uj5u.com熱心網友回復:
我不認為這與 c# 與 VB.Net 有太大關系,一旦構建就應該只有 .Net 程式集,并且使用哪種語言無關緊要。
正確的解決方案應該是為Microsoft.SqlServer.Types需要此程式集的專案注冊 nuget 依賴項。即轉到“Tools\Nuget Package Manager\Manage packages for solution”并在您的 dolphin 專案中安裝上面的包。
這應該確保所需的 dll 從 Internet 下載并復制到您的輸出目錄,但如果您使用任何型別的安裝框架,您可能需要手動包含它。
uj5u.com熱心網友回復:
我已經找到了解決方案。這是winforms的解決方案。我只在網上看到過 Azure 或 WFC 或 asp.net 的解決方案,所以希望這可以作為其他人的指南。它要求解決方案中的所有專案都是 64 位的,但對我來說這沒問題。我采取的步驟是:
- 將所有專案更改為 x64
- 使用 nuget 將 Microsoft.SqlServer.Types 添加到解決方案中涉及 SQL 空間型別的所有專案。
- 在 app.config 中,包括以下內容:
<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>
- 在代碼的早期,在應用程式中,在需要任何 SQL 空間型別之前,執行以下代碼(這是安裝包后顯示的自述頁面底部的 nuget 建議的代碼):
using System.Reflection;
...
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
- 在您的安裝軟體中,確保
<yourexename>.exe.config已部署到 %APPFOLDER%(您的應用程式部署到的檔案夾)。 - 此外,在 %APPFOLDER% 中包含檔案:
Microsoft.SqlServer.Types.dll - 此外,在 %APPFOLDER% 中,您需要以下結構(您應該能夠從專案檔案夾中復制):
%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)
如果有人將其改編為 32 位,如果您愿意將其發布在下面,這對我也很有用。謝謝。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/314906.html
標籤:c# sql-server vb.net dll
