开发者

Word 2007 AddIn does not work with 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 sys开发者_运维知识库tem 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.


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.


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


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

        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜