visual studio shell SelectionEvents OnChange事件丢失问题
2016-11-17 11:30
344 查看
解决办法如下:
http://stackoverflow.com/questions/14165885/add-in-events-are-never-executed
http://stackoverflow.com/questions/14165885/add-in-events-are-never-executed
down vote | If you look at applicationObject in the debugger you'll see its a COM object, but the xxxEvents classes are not (If you can't get the code to break on OnConnection, then possibly your addin isn't getting loaded when you debug, check the tools menu) Events in COM are handled by a separate COM interface (several in this case) in the other direction which the server (VS) calls to fire them. Although COM objects have a similar typed assembly concept to CLR assemblies they are unmanaged code internally, so cannot hold roots to managed objects. So although you can hook a delegate to a COM event in a way that looks exactly like a native CLR event, your event is hooked to an RCW (runtime callable wrapper). There is a COM reference from the server to the RCW com interface, but without a CLR root the RCW eventually gets disposed which unloads the com interface, after which you won't sink any events. I'm not sure but I think this normally works when you consume a single COM object with a direct association to its event interfaces so its maybe due to how the DTE COM interface is structured... Anyway as others have said you just need any kind of managed reference to the BuildEvents, SelectionEvents and DocumentEvents classes from the app object to fix it. Multiple instances of VS load separate instances of the add in so you could just add a list of static object refs and set them in OnConnect. Subscription to DTE events doesn't seem to work - Events don't get called http://msdn.microsoft.com/en-us/library/k639e386.aspx |
1down vote | If you look at applicationObject in the debugger you'll see its a COM object, but the xxxEvents classes are not (If you can't get the code to break on OnConnection, then possibly your addin isn't getting loaded when you debug, check the tools menu) Events in COM are handled by a separate COM interface (several in this case) in the other direction which the server (VS) calls to fire them. Although COM objects have a similar typed assembly concept to CLR assemblies they are unmanaged code internally, so cannot hold roots to managed objects. So although you can hook a delegate to a COM event in a way that looks exactly like a native CLR event, your event is hooked to an RCW (runtime callable wrapper). There is a COM reference from the server to the RCW com interface, but without a CLR root the RCW eventually gets disposed which unloads the com interface, after which you won't sink any events. I'm not sure but I think this normally works when you consume a single COM object with a direct association to its event interfaces so its maybe due to how the DTE COM interface is structured... Anyway as others have said you just need any kind of managed reference to the BuildEvents, SelectionEvents and DocumentEvents classes from the app object to fix it. Multiple instances of VS load separate instances of the add in so you could just add a list of static object refs and set them in OnConnect. Subscription to DTE events doesn't seem to work - Events don't get called http://msdn.microsoft.com/en-us/library/k639e386.aspx |
相关文章推荐
- 解决在Microsoft Visual Studio .NET 2003页面切换按钮等事件丢失的问题
- 解决在Microsoft Visual Studio .NET 2003页面切换按钮等事件丢失的问题
- 安装Microsoft Visual Studio 2005 Extensions for Windows Workflow Foundation的工具箱控件丢失问题解决~~
- onorientationchange事件的问题
- Visual Studio .NET 中处理 Office 2003 Web(SpreadSheet等) 组件的事件
- 解决Microsoft Visual Studio Code Name "Orcas" 不能安装的问题
- Visual Studio .NET 无法创建应用程序 。问题很可能是因为本地 Web 服务器上没有安装所需的组件
- "Visual studio .net 无法创建或打开应用程序" 问题的一个解决思路
- 关于用户控件事件丢失问题解决
- “Visual Studio .NET 已检测到指定的 Web 服务器运行的不是 ASP.NET 1.1 版...”问题的解决办法
- “Visual Studio.net已检测到指定的Web服务器运行的不是Asp.net1.1版。您将无法运行Asp.net Web应用程序或服务”问题的解决方法
- “Visual Studio.net已检测到指定的Web服务器运行的不是Asp.net1.1版。您将无法运行Asp.net Web应用程序或服务”问题的解决方法
- Safe! Repel Attacks on Your Code with the Visual Studio 2005 Safe C and C++ Libraries
- Tool Gives Visual Studio Developers Jump on Writing Linux Apps
- Tool Gives Visual Studio Developers Jump on Writing Linux Apps
- Visual Studio.net 2003安装提示重启问题
- Borland Together for Visual Studio.Net V2.0 安装问题
- “Visual Studio .NET 无法创建或打开应用程序。问题很可能是因为本地WEB本地服务器上没有安装所需的组件。请运行Visual Studio .NET安装程序并添加WEB开发组件“的一种解决方案
- Visual Studio.NET 已检测到指定的Web服务器运行的不是ASP.NET1.1版的问题。
- 问题很可能是因为本地 Web 服务器上没有安装所需的组件。请运行 Visual Studio .NET 安装程序并添加 Web 开发组件。