You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

WIX安装程序自定义动作加载Microsoft.Data.SqlClient.SNI.x86.dll失败(0x8007007E)如何修复?

Fix: "Cannot load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll'" in Wix Custom Action

I’ve run into this exact issue before with Wix custom actions and Microsoft.Data.SqlClient—let’s break down why this happens and how to fix it:

The console app works because it automatically resolves the SNI (Sql Native Interface) DLL from its output directory, but Wix MSIs don’t include these native dependencies by default. Here’s your step-by-step fix:

1. Include the SNI DLLs in your MSI package

The Microsoft.Data.SqlClient.SNI.x86.dll (and x64 variant if you support 64-bit) is a native DLL tucked away in your NuGet package’s runtime folders.

  • Locate the DLLs in your project’s NuGet packages:
    For x86: packages/Microsoft.Data.SqlClient.SNI.[version]/runtimes/win-x86/native/Microsoft.Data.SqlClient.SNI.x86.dll
    For x64: packages/Microsoft.Data.SqlClient.SNI.[version]/runtimes/win-x64/native/Microsoft.Data.SqlClient.SNI.x64.dll
  • Add these DLLs to your Wix project using one of two reliable methods:
    Option A: Embed as a binary resource for your custom action:
    <Binary Id="SqlSniX86" SourceFile="path/to/Microsoft.Data.SqlClient.SNI.x86.dll" />
    
    Option B: Install to the same directory as your custom action DLL (most reliable for runtime loading):
    <Component Id="SqlSniX86Comp" Guid="YOUR-UNIQUE-GUID-HERE">
      <File Id="SqlSniX86File" Source="path/to/Microsoft.Data.SqlClient.SNI.x86.dll" KeyPath="yes" />
    </Component>
    
    Don’t forget to include this component in your feature so it gets installed with your MSI.

2. Match platform architecture exactly

  • If your MSI is built as x86, only include the x86 SNI DLL. If it’s x64, use the x64 variant. Mixing architectures will trigger the "module not found" error even if the DLL is present.
  • Double-check your Wix project’s platform target matches the SNI DLL you’re including.

3. Ensure the custom action context can find the DLL

  • For immediate custom actions (run in system context), make sure the SNI DLL is either in the system PATH or your custom action’s working directory is set to the folder where the DLL is installed.
  • For deferred custom actions, confirm the DLL is installed before the action runs—deferred actions execute after files are copied to the target machine, so timing matters.

4. Verify your NuGet references

  • In your custom action project, set Copy Local to True for Microsoft.Data.SqlClient and Microsoft.Data.SqlClient.SNI packages. This ensures the DLLs are copied to your project’s output directory, making them easier to reference in Wix.
  • Avoid "No Copy" settings for these dependencies—Wix won’t pick them up automatically otherwise.

5. Quick temporary alternative (if applicable)

If you don’t strictly need Microsoft.Data.SqlClient, you could switch back to System.Data.SqlClient (the older, deprecated library). Its SNI dependencies are often pre-installed on Windows systems, which might bypass the DLL loading issue. Note this is a stopgap, as System.Data.SqlClient is no longer maintained.

After making these changes, rebuild your MSI and use Orca to verify:

  • If you used Option B, check the File table for the SNI DLL entry.
  • If you used Option A, check the Binary table for the embedded DLL.

内容的提问来源于stack exchange,提问作者Silny ToJa

火山引擎 最新活动