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

在Visual Studio 2022的VB.NET中读取.msg文件时遇程序集加载错误

解决VB.NET读取.msg文件时的Office程序集加载错误

错误原因

你遇到的System.IO.FileNotFoundException是因为程序找不到指定版本(15.0.0.0)的Office程序集,通常是Office安装缺失、引用版本不匹配导致的。

解决步骤

1. 检查本地Office安装

  • 确认已安装Microsoft Office 2013及以上版本(版本15.0对应Office 2013),且安装时包含Outlook组件。
  • 如果安装的是更高版本(如Office 2016/365,对应版本16.0),需要调整项目引用适配当前版本。

2. 修正项目引用

  • 打开Visual Studio 2022,右键项目 → 管理NuGet程序包,搜索并安装Microsoft.Office.Interop.Outlook。
  • 若之前手动添加过COM引用,先在项目的引用列表中移除所有Office/Outlook相关项,再通过NuGet重新安装,避免版本冲突。

3. 添加程序集绑定重定向(可选)

若安装的Office版本与错误中的15.0不一致,可在App.config中添加绑定重定向,让程序自动适配已安装版本:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="office" publicKeyToken="71e9bce111e9429c" culture="neutral" />
      <!-- 把newVersion改为你实际安装的Office版本号,16.0对应Office 2016/365 -->
      <bindingRedirect oldVersion="0.0.0.0-16.0.0.0" newVersion="16.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

4. 不依赖Office的替代方案

如果不想依赖本地Office环境,可使用纯.NET库读取.msg文件:

  • 通过NuGet安装MsgReader库。
  • 替换代码为:
Imports MsgReader.Outlook
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filePath As String = "C:\Email\Source\Tet.msg"
        Using reader As New Storage(filePath)
            Dim subject As String = reader.Subject
            Dim body As String = reader.BodyText
            ' 后续处理逻辑
        End Using
    End Sub
End Class

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 00:00:14