如何在对 Visual Studio 调试器可视化工具的调用之间保留自定义对象?
我需要在调用我正在编写的调试器可视化工具之间保留一个对象,但它不需要在 IDE 会话之间保留。 IDE 的 EnvDTE.Globals 对象似乎是存储该对象的明显位置。
如果所存储的对象的类型已加载到 IDE 中(例如整数列表),我可以成功地将这种类型的变量保存在全局对象中,然后在后续调用调试器可视化工具时检索它。
但是,如果要保存的变量的类型是在包含调试器可视化工具本身的程序集中或在可视化工具引用的本地程序集中声明的,那么一切都会出错。我可以将对象保存到全局变量中,并在对可视化工具的同一调用中检索它。但是,当我尝试在后续调用中访问它时,我可以成功测试该值是否存在,但当我尝试访问它时,IDE 崩溃了。
我认为发生的情况是每次使用可视化工具时都会重新加载调试器可视化工具的程序集,因此存储对象的类型与我期望的类型不匹配。嗯,这是我的猜测。任何解释/解决方法将不胜感激。
I need to persist an object between calls to a debugger visualizer I'm writing, but it doesn't need to persist between IDE sessions. The EnvDTE.Globals object for the IDE seemed like an obvious place to store this object.
If the type of the object being stored is already loaded in the IDE, e.g. a list of integers, I can successfully save a variable of this type in the globals object, and then retrieve it on a subsequent call to the debugger visualizer.
However, if the type of the variable being saved is declared in the assembly containing the debugger visualizer itself, or in a local assembly referenced by the visualizer, then it all goes horribly wrong. I can save the object into the globals, and retrieve it within the same call to the visualizer. However, when I try to access it in a subsequent call I can successfully test the value exists, but when I try to access it the IDE falls over.
I presume that what is happening is the assembly for the debugger visualizer is reloading each time the visualizer is used, and so the type of the stored object isn't matching the type I'm expecting. Well, that's my guess. Any explanations/workarounds would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过序列化/反序列化对象并存储序列化结果而不是对象?
Have you tried to serialize/de serialize the object and store the serialization result instead of the object?
我想维护一个 WCF 回调对象,并且让远程客户端即使在调试器扩展未处于活动状态时也能够回调。因此,存储对象的序列化版本在这种特定情况下没有帮助。
I wanted to maintain a WCF callback object, and have the remote client be able to call back even when the debugger extension wasn't active. So storing a serialized version of the object wouldn't help in this particular instance.