如何确定TransparentProxy是否指向有效实例
有没有办法确定 TransparentProxy
是否指向有效的引用?
我有IPlugin
。我创建一个新的 AppDomain,使用 IPlugin
的实现加载程序集,并创建该实现的实例。我收到一个 IPlugin
,但其内部是 TransparentProxy
。如果我卸载辅助 AppDomain,IPlugin
的实例(代理指向的实例)就会消失。但代理仍然指向那里。当我尝试访问代理时,我的程序崩溃(无一例外)。
伪代码:
var domain = CreateDomain("domain");
var assembly = domain.LoadAssembly("myAssembly");
var plugin = domain.CreateObject("MyPlugin") as IPlugin;
// plugin is really a TransparentProxy to a MyPlugin
if (plugin != null)
plugin.DoSomething("123");
UnloadDomain(domain);
if (plugin != null) // Still evaluates to TRUE!
plugin.DoSomething("123"); // Program crashes with no exceptions
Is there a way to determine whether a TransparentProxy
is pointing to a valid reference?
I have IPlugin
. I create a new AppDomain, load the assembly with an implementation of IPlugin
, and create an instance of that implemenation. I receive a IPlugin
, but under the covers its TransparentProxy
. If I unload the secondary AppDomain, the instance of IPlugin
(the one that the proxy points to) is gone. But the proxy is still pointing there. My program crashes (with no exceptions) when I try to access the proxy.
Psudeocode:
var domain = CreateDomain("domain");
var assembly = domain.LoadAssembly("myAssembly");
var plugin = domain.CreateObject("MyPlugin") as IPlugin;
// plugin is really a TransparentProxy to a MyPlugin
if (plugin != null)
plugin.DoSomething("123");
UnloadDomain(domain);
if (plugin != null) // Still evaluates to TRUE!
plugin.DoSomething("123"); // Program crashes with no exceptions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,既然没有人提出正确的答案,你可以试试这个:
Well, since no one has suggested a proper answer, you could try this: