简体   繁体   English

Microsoft.Office.Interop.Word命名空间覆盖我的System命名空间? C#ASP.net

[英]Microsoft.Office.Interop.Word namespace overriding my System namespace? C# ASP.net

I am trying to fix this legacy app that was created using Visual Studio 2003, using Microsoft Office Interops version 11, .NET 2.0. 我试图修复使用Visual Studio 2003,Microsoft Office Interops版本11,.NET 2.0创建的旧应用程序。 I am trying to fix it in Visual Studio Express 2010 to reference Interops version 14, .NET 4.0 -- as noted in my previous question on StackOverflow, the legacy app works fine in Windows 7 but after I close it, the Microsoft Office products are crashing when I try to use them. 我正在尝试在Visual Studio Express 2010中修复它,以引用Interops版本14,.NET 4.0-正如我在StackOverflow上一个问题中提到的那样,旧版应用程序在Windows 7中运行正常,但是在关闭它之后,Microsoft Office产品被当我尝试使用它们时崩溃。

However, when I fix the references in VS2010 (delete old v.11 Interops, add in new v.14 Interops) and then attempt to publish the application, I get errors like 但是,当我在VS2010中修复引用时(删除旧的v.11 Interops,添加新的v.14 Interops),然后尝试发布应用程序时,出现类似以下错误

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

It looks like VS2010 does not see my System namespace being used when the Word namespace is referenced? 看起来当引用Word名称空间时,VS2010没有看到我的系统名称空间被使用? When I removed the 当我删除

using Microsoft.Office.Interop.Word

namespace and then try to publish, the errors like the above disappear and I only get the expected errors related to the missing Word reference like 命名空间,然后尝试发布,上面的错误消失了,而我只得到了与缺少的Word参考相关的预期错误,例如

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

I already included the System.dll in the reference so I'm not sure what's going on? 我已经在参考中包含System.dll,所以我不确定发生了什么? Thanks for reading! 谢谢阅读!

EDIT: I made "Embeded Interop Types" to be False for the Office Interops. 编辑:我使“嵌入式互操作类型”为Office互操作为False。 That may have fixed some of the errors? 那可能已经修复了一些错误? HOWEVER: Visual Studio is still interpreting any System references to be "Microsoft.Office.Interop.Word.System" which is NOT what I want. 但是:Visual Studio仍将任何系统引用解释为“ Microsoft.Office.Interop.Word.System”,这不是我想要的。 This error seems to be the dominant one now: 此错误现在似乎是主要错误:

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

This issue occurs to me, only when i put the using stuff after the namespace definition like this : 仅当我将使用内容放在这样的名称空间定义之后时,我才会发生此问题:

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;
..........................

And the right way is : 正确的方法是:

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
{
....................

May it helps you! 愿它对您有帮助!

To fix the issue in your namespaces: 要解决您的命名空间中的问题,请执行以下操作:

change: 更改:

using Microsoft.Office.Interop.Word;

to: 至:

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

Do the same for other objects you might be using from any other conflicting namespace. 对可能从任何其他冲突名称空间使用的其他对象执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM