Activator.GetObject - MarshalByRefObject

发布于 2024-07-08 16:12:28 字数 613 浏览 5 评论 0原文

在.Net Activator.GetObject(Type type, string url, object data)中返回对象的代理。 我猜代理继承自 MarshalByRefObject 并且可以跨 AppDomains 发送。 我对吗?

在我的应用程序中,我在应用程序域 A 中创建一个对象并在应用程序域 B 中使用它。该对象的成员是使用 Activator.GetObject () 创建的代理对象。 因此,当我在 AppDomain B 中时,我对在 AppDomain A 中创建的对象有一个透明代理。当我尝试在代理对象上执行调用方法时,我遇到了错误。

例如,我在应用程序域 B 中创建一个连接对象。我在应用程序域 A 中拥有连接对象的透明代理。当我尝试从应用程序域 A 进行这样的调用时,我会遇到错误。ConnectionObject.SecurityProxy.GetSecurityAccount ( )。 看起来问题是当我尝试进行像上面这样的调用时,它试图在 AppDomain A 中再次创建 SecurityProxy,而不是将调用转发到 AppDomain B。当连接时,安全代理已经在 AppDomain B 中创建对象已创建。

你能帮我弄清楚我做错了什么吗?

问候, 阿尼尔.

In .Net Activator.GetObject(Type type, string url, object data) returns a proxy to the object. I guess that proxy inherits from MarshalByRefObject and can be sent across AppDomains. Am I right?

In my app, I am creating an object in appdomain A and using it appdomain B. The object's members are proxyobjects created using Activator.GetObject (). so, when I am in AppDomain B, I have a transparent proxy to the object created in appdomain A. When I try to execute a call the method on the proxy objects, I am running into errors.

For Example, I Create a Connection object in App Domain B. I have the transparent proxy for the Connection object in App Domain A. I run in to error when I try to make a call like this from AppDomain A. ConnectionObject.SecurityProxy.GetSecurityAccount( ). looks like the problem is When I try to make a call like the one above, it is trying to create the SecurityProxy again in AppDomain A instead of forwarding the call to AppDomain B. The security proxy has already been created in AppDomain B when the connection object was created.

Could you please help me figure out what I am doing wrong?

Regards,
Anil.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2024-07-15 16:12:28

假设 SecurityProxy 是 ConnectionObject 上的一个属性...

您正在处理域 A 中的 ConnectionObject 代理。方法调用将转发到域 B,在域 B 中执行它们,并将结果返回到域 A。

属性是编译器诡计。 它使 get_X 和 set_X 这两个方法看起来像一个字段。

因此,当您调用“ConnectionObject.SecurityProxy”时,您正在调用一个跨应用程序域边界返回 SecurityProxy 实例的方法。

您必须执行以下两件事之一:创建并解开 SecurityProxy 的实例并将其交给 ConnectionObject,或者将 ConnectionObject 转换为仅公开方法并仅返回您绝对知道可以安全跨越应用程序域边界的类型/参数的外观。

Assuming that SecurityProxy is a property on ConnectionObject...

You're dealing with the ConnectionObject proxy in domain A. Method calls are forwarded to domain B, where they are executed, and the results are returned to domain A.

A property is a compiler trick. It makes two methods, get_X and set_X, appear to be a field.

So, when you call "ConnectionObject.SecurityProxy" you are calling a method that returns an instance of SecurityProxy across the appdomain boundary.

You must do one of two things: Create and unwrap an instance of SecurityProxy and hand it to ConnectionObject, or turn ConnectionObject into a facade that only exposes methods and only returns types/takes arguments that you absolutely know are safe to cross appdomain boundaries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文