2011-03-27 143 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。進行更改後問題得到解決。