【问题标题】:Under what conditions will `RealProxy.GetTransparentProxy()` return `null`?`RealProxy.GetTransparentProxy()` 在什么情况下会返回 `null`?
【发布时间】:2010-12-23 17:37:55
【问题描述】:

http://msdn.microsoft.com/en-us/library/system.runtime.remoting.proxies.realproxy.gettransparentproxy%28v=VS.100%29.aspx 的文档并未指出GetTransparentProxy 将返回null 的情况,但是当我调用它时,我得到了null

什么情况会导致这种行为?

【问题讨论】:

    标签: c# .net proxy-classes realproxy


    【解决方案1】:

    没关系,解决了。 关键让您的RealProxy 派生类调用具有要代理的类型的基本构造函数。就我而言:

    public class MyProxy<T> : RealProxy
    {
        public MyProxy()
            : base(typeof(T))    // this was missing
        {
            ...
        }
    
        ...
    }
    

    【讨论】:

    • 我今天又一次遇到了这个问题。遇到此问题的其他人请注意——Microsoft .NET 返回 null,但 Mono 会引发异常。
    猜你喜欢
    • 2020-02-07
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    相关资源
    最近更新 更多