Word 2007 加载项不适用于 Word 2010

发布于 2024-10-27 05:28:59 字数 1506 浏览 5 评论 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 系统上可用的问题,我不知道如何解决此问题。我做了一些谷歌搜索,但没有发现任何有趣的结果。请帮忙。

I've written an add-in for Word 2007 in C#. To distribute the add-in I employed the ClickOnce installer. However, this add-in doesn't work with Word 2010. It produces the following error in the vsto.log file:

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

While I understand that there is a version mismatch between the Microsoft.Office.Interop.Word dll the add-in looks for and the one available on the system with Word 2010, I have no idea how I could fix this issue. I did some Google searching but nothing interesting came up. Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

辞慾 2024-11-03 05:28:59

我最终成功找到了问题所在。很抱歉没有早点发布相关信息。看来我链接到了错误的库而不是导致此问题的 PIA 库。进行更改后问题得到解决。

I've managed to trace down the problem in the end. Sorry for not posting about it sooner. It seems I was linking to the wrong libraries instead of the PIA ones which caused this problem. The problem was fixed after making the change.

七禾 2024-11-03 05:28:59

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

I believe you have to turn off the specific Version check for those word assemblies in the click once install project.

懒猫 2024-11-03 05:28:59

首先使用以下代码检查您的系统中是否安装了 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。并运行下面的代码

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

        }
    }

First Check PIA(primary Interop Assembly) is installed in your system using below code

   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;
    }

Then download office PIA from http://www.microsoft.com/download/en/details.aspx?id=18346. and run below code

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

        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文