2012-07-13 89 views
2

我正在尝试修复使用Visual Studio 2003创建的传统应用程序,使用Microsoft Office Interops版本11,.NET 2.0。我试图在Visual Studio Express 2010中修复它,以引用Interops版本14,.NET 4.0--正如我在StackOverflow上的上一个问题所述,传统应用程序在Windows 7中工作正常,但在关闭它之后,Microsoft Office产品当我尝试使用它们时崩溃。Microsoft.Office.Interop.Word命名空间覆盖我的系统命名空间? C#ASP.net

然而,当我修复VS2010引用(删除旧V.11互操作性展示,加入新的第14节互操作性展示),然后尝试发布应用程序,我得到这样的错误

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

它看起来像VS2010在引用Word命名空间时看不到我的系统命名空间?当我删除了

using Microsoft.Office.Interop.Word 

名称空间,然后尝试发布,像上面的错误消失,我只得到有关失踪字引用预期的错误,如

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

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

编辑:我做了“Embeded Interop Types”为Office Interops的错误。这可能修复了一些错误?但是:Visual Studio仍然将任何系统引用解释为“Microsoft.Office.Interop.Word.System”,这不是我想要的。这个错误似乎是现在占主导地位:发生在我

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

回答

5

这个问题,只有当我把使用的东西的名称空间定义,比如后:

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

它可以帮助你!

0

要解决此问题在您的命名空间:

变化:

using Microsoft.Office.Interop.Word; 

到:

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

做你可能从任何其他冲突的命名空间可以使用其它的对象一样。