VSTO AssemblyResolve issue

只愿长相守 提交于 2020-05-31 10:16:10

问题


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?


回答1:


Be aware, you develop a add-in, not a standalone applicaton where you can manage references at runtime and do whatever you need. You may consider adding the binding information to the application config file (in your case it will be Word.exe.config).




回答2:


You can add handler in AddIn_Startup code. Code is in VB.net.

AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf AssemblyResolver



回答3:


I have just had this problem, landed here from searching and then had a look around the VSTO Microsoft.Tools AddinBase Class (I hope this is the right link). In any case I am Overriding the Begininit and setting AppDomain.CurrentDomain.AssemblyResolve there. For my case this is early enough to load my reference.

However, please note that the addin can still try to load your assembly (and fail) if it needs it and this can happen even before Begininit. For example if you refer to an Enum or Const from your Assembly in the ThisAddin class.



来源:https://stackoverflow.com/questions/29675802/vsto-assemblyresolve-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!