【问题标题】:Microsoft.Office.Interop.Word namespace overriding my System namespace? C# ASP.netMicrosoft.Office.Interop.Word 命名空间覆盖我的系统命名空间? C# ASP.NET
【发布时间】:2026-01-24 21:25:01
【问题描述】:

我正在尝试使用 Microsoft Office Interops 版本 11、.NET 2.0 修复使用 Visual Studio 2003 创建的旧版应用程序。我正在尝试在 Visual Studio Express 2010 中修复它以引用 Interops 版本 14、.NET 4.0 - 正如我之前关于 * 的问题中所述,旧版应用程序在 Windows 7 中运行良好,但在我关闭它之后,Microsoft Office 产品是当我尝试使用它们时崩溃。

但是,当我修复 VS2010 中的引用(删除旧的 v.11 互操作,添加新的 v.14 互操作)然后尝试发布应用程序时,我收到类似的错误

'Microsoft.Office.Interop.Word.System does not contain a definition for IO'

当引用 Word 命名空间时,VS2010 似乎没有看到我的系统命名空间被使用?当我删除

using Microsoft.Office.Interop.Word

命名空间,然后尝试发布,上面的错误消失了,我只得到与缺少的 Word 参考相关的预期错误,如

The type or namespace name '_Document' could not be found (are you missing a using directive or an assembly reference?)

我已经在参考中包含了 System.dll,所以我不确定发生了什么?感谢阅读!

编辑:对于 Office 互操作,我将“嵌入式互操作类型”设置为 False。那可能已经修复了一些错误?但是:Visual Studio 仍在将任何系统引用解释为“Microsoft.Office.Interop.Word.System”,这不是我想要的。这个错误现在似乎是主要错误:

The type name 'Windows' does not exist in the type 'Microsoft.Office.Interop.Word.System'

【问题讨论】:

    标签: c# .net ms-office .net-assembly primary-interop-assembly


    【解决方案1】:

    这个问题发生在我身上,只有当我像这样将 using 的东西放在命名空间定义之后:

    namespace Addin
    {
    using Microsoft.Office.Core;
    using Microsoft.Office.Interop.Word;
    using Microsoft.Win32;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Net;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    ..........................
    

    正确的方法是:

    using Microsoft.Office.Core;
    using Microsoft.Office.Interop.Word;
    using Microsoft.Win32;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Net;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace Addin
    {
    ....................
    

    希望对你有帮助!

    【讨论】:

      【解决方案2】:

      要解决命名空间中的问题:

      改变:

      using Microsoft.Office.Interop.Word;
      

      到:

      using Document = Microsoft.Office.Interop.Word.Document;
      

      对您可能从任何其他冲突命名空间使用的其他对象执行相同操作。

      【讨论】: