2011-03-27 66 views
0

我已经为C#中的Word 2007编写了一个加载项。要分发加载项,我使用了ClickOnce安装程序。虽然我明白,存在Microsoft.Office.Interop之间的版本不匹配Word 2007 AddIn不适用于Word 2010

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified. 
File name: 'Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' 
    at Microsoft.VisualStudio.Tools.Office.Word.Internal.IWordHostItemProviderProxy..ctor(IHostItemProviderExtendedContract hostItemProvider) 
    at Microsoft.VisualStudio.Tools.Office.Word.Internal.IWordHostItemProviderProxy.GetProxy(IHostItemProviderExtendedContract contract) 
    at Microsoft.VisualStudio.Tools.Office.Word.Internal.LocalWordServiceProvider.GetService(Type serviceType) 
    at Microsoft.VisualStudio.Tools.Applications.Internal.LocalServiceProvider.System.IServiceProvider.GetService(Type serviceType) 
    at Microsoft.VisualStudio.Tools.Office.EntryPointComponentBase.Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint.Initialize(IServiceProvider hostContext) 
    at Microsoft.VisualStudio.Tools.Applications.AddInAdapter.ExecutePhase(ExecutionPhases executionPhases) 
    at Microsoft.VisualStudio.Tools.Office.Internal.OfficeAddInAdapterBase.InitializeEntryPointsHelper() 

:然而,这种外接不能与Word 2010的工作,它产生以下错误在vsto.log文件。 Word的DLL的加载项寻找和在Word 2010系统上可用的,我不知道如何解决这个问题。我做了一些谷歌搜索,但没有什么有趣的。请帮忙。

+0

您使用的是VSTO和.NET的哪个版本? – dan9298 2011-05-19 12:04:38

回答

0

我相信你必须关闭click once install项目中那些字组件的特定版本检查。

+0

已经尝试过。它不起作用:| – AlgolDocks 2011-04-10 11:09:24

0

首先检查PIA(主互操作程序集)安装在你的系统中使用下面的代码

bool IsPrimaryInteropAssembliesInstalled() 
    { 
     try 
     { 
      if (Assembly.Load("Policy.11.0.Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") != null) 
      { 
       return true; 
      } 
     } 
     catch (Exception) 
     { 
     } 
     return false; 
    } 

然后从http://www.microsoft.com/download/en/details.aspx?id=18346下载Office PIA。并运行下面的代码

void InstallPrimaryInteropAssemblies() 
    { 
     try 
     { 
      string str = "path\o2007pia.msi"; 
      System.Diagnostics.Process process = new System.Diagnostics.Process 
      { 
       StartInfo = { FileName = str } 
      }; 
      process.Start(); 
      while (!process.HasExited) 
      { 
       System.Threading.Thread.Sleep(0x3e8); 
      } 
     } 
     catch (Exception exception) 
     { 

     } 
    } 
1

我已经设法追查到底的问题。对不起,不要提早发布。看来我连接到错误的库,而不是导致这个问题的PIA。进行更改后问题得到解决。