Word 2007 AddIn不适用于Word 2010

时间:2011-03-27 18:05:49

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

我在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的系统上可用的版本不匹配,但我不知道如何解决此问题。我做了一些谷歌搜索但没有任何有趣的事情出现。请帮忙。

3 个答案:

答案 0 :(得分:1)

我最终设法追查了这个问题。很抱歉没有尽快发布。似乎我链接到错误的库而不是导致这个问题的PIA。这个问题在做出改变后得到了解决。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

使用以下代码

在系统中安装首次检查PIA(主要Interop Assembly)
   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下载办公室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)
        {

        }
    }
相关问题