0

我用 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 之间存在版本不匹配,但我不知道如何解决此问题。我做了一些谷歌搜索,但没有发现任何有趣的东西。请帮忙。

4

3 回答 3

1

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

于 2011-08-01T13:29:03.003 回答
0

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

于 2011-03-28T16:16:54.870 回答
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)
        {

        }
    }
于 2011-07-25T10:23:34.273 回答