You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Outlook Interop加载Office程序集失败问题求助

Fix Outlook Interop Issues in .NET Core WinForms

Step 1: Use the Official NuGet Package

  • Remove any existing COM references to Outlook from your project.
  • Uninstall outdated Microsoft.Office.Interop.Outlook NuGet packages if present.
  • Install the latest Microsoft.Office.Interop.Outlook package via NuGet Package Manager. This package provides pre-built interop assemblies optimized for .NET Core, avoiding the compilation errors that come with direct COM references.

Step 2: Resolve Assembly Version Mismatch

If you still encounter the Could not load file or assembly 'office, Version=15.0.0.0' error, add an assembly binding redirect to your app.config file to map the requested version to the one installed on your machine:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="office" publicKeyToken="71e9bce111e9429c" culture="neutral" />
      <!-- Replace "16.0.0.0" with your installed Office version (16 for 2016/365, 15 for 2013) -->
      <bindingRedirect oldVersion="0.0.0.0-16.0.0.0" newVersion="16.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Step 3: Match Platform Target to Office Installation

Office is often installed as 32-bit even on 64-bit systems. Align your project's platform target to avoid runtime conflicts:

  1. Right-click your project → Properties → Build.
  2. Under "Platform target", select x86 if Office is 32-bit, or x64 if it's 64-bit.
  3. Uncheck "Prefer 32-bit" if enabled.

Step 4: Fix Code & Clean Up COM Objects

Adjust your VB code to replace placeholder variables and properly release COM objects (to prevent lingering Outlook processes):

Imports Microsoft.Office.Interop.Outlook

' ...

Dim outlookApp As Outlook.Application = Nothing
Dim mail As Outlook.MailItem = Nothing

Try
    outlookApp = New Outlook.Application()
    mail = CType(outlookApp.CreateItem(OlItemType.olMailItem), MailItem)
    
    ' Replace strExportFileName with your actual file name variable
    mail.Subject = $"Envoi du fichier '{strExportFileName}'"
    mail.Body = ""
    mail.[To] = ""
    
    ' Replace strExportFilePath with your actual file path variable
    Dim attachmentPath As String = strExportFilePath
    mail.Attachments.Add(attachmentPath, OlAttachmentType.olByValue, Type.Missing, Type.Missing)
    
    mail.Display(True)
Finally
    ' Clean up COM objects to avoid memory leaks
    If mail IsNot Nothing Then
        System.Runtime.InteropServices.Marshal.ReleaseComObject(mail)
    End If
    If outlookApp IsNot Nothing Then
        System.Runtime.InteropServices.Marshal.ReleaseComObject(outlookApp)
    End If
End Try

Note: Ensure Microsoft Outlook is installed on the target machine, and the user running the app has permissions to launch and access Outlook.

内容的提问来源于stack exchange,提问作者8oris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 14:59:59