2

We develop a VSTO plugin for Word and we have the problem that the earliest entry point of the addin is the AddIn_Startup handler. The issue is that this handler is called too late for the AssemblyResolve handler we implemented to find the needed assemblies.

I sovled the problem by assigning the handler to the AppDomain.CurrentDomain.AssemblyResolve event in the Addins.Designer.cs class, but as you all know, this code is autogenerated.

Is there a way to assign the AssemblyResolve Handler sooner as in the AddIn_Startup handler and in a not autogenerated file?

4

3 回答 3

0

请注意,您开发的是一个插件,而不是一个独立的应用程序,您可以在其中管理运行时引用并执行您需要的任何操作。您可以考虑将绑定信息添加到应用程序配置文件(在您的情况下,它将是 Word.exe.config)。

于 2015-04-16T13:49:31.000 回答
0

您可以在 AddIn_Startup 代码中添加处理程序。代码在 VB.net 中。

AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf AssemblyResolver
于 2015-04-20T13:02:28.390 回答
0

我刚刚遇到这个问题,通过搜索来到这里,然后查看了 VSTO Microsoft.Tools AddinBase 类(我希望这是正确的链接)。在任何情况下,我都将覆盖 Begininit 并在那里设置 AppDomain.CurrentDomain.AssemblyResolve。就我而言,这已经足够早加载我的参考资料了。

但是,请注意,插件仍然可以在需要时尝试加载您的程序集(并失败),这甚至可能在 Begininit 之前发生。例如,如果您在 ThisAddin 类中从您的程序集中引用 Enum 或 Const。

于 2020-05-29T07:45:50.407 回答