【问题标题】:Word 2007 AddIn does not work with Word 2010Word 2007 加载项不适用于 Word 2010
【发布时间】:2011-03-27 18:05:49
【问题描述】:

我用 C# 为 Word 2007 编写了一个插件。为了分发插件,我使用了 ClickOnce 安装程序。但是,此加载项不适用于 Word 2010。它会在 vsto.log 文件中产生以下错误:

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()

虽然我了解加载项查找的 Microsoft.Office.Interop.Word dll 与 Word 2010 系统上可用的 dll 之间存在版本不匹配,但我不知道如何解决此问题。我做了一些谷歌搜索,但没有发现任何有趣的东西。请帮忙。

【问题讨论】:

  • 您使用的是什么版本的 VSTO 和 .NET?

标签: c# .net vsto add-in office-2010


【解决方案1】:

我最终设法找到了问题所在。很抱歉没有早点发布。似乎我链接到了错误的库而不是导致此问题的 PIA 库。修改后问题已解决。

【讨论】:

    【解决方案2】:

    我相信您必须在 click once install 项目中关闭这些单词程序集的特定版本检查。

    【讨论】:

      【解决方案3】:

      首先使用以下代码检查 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)
              {
      
              }
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-23
        • 1970-01-01
        • 2012-07-30
        相关资源
        最近更新 更多