C# 为什么可以';我不能访问ClientBase的这个公共属性吗?

C# 为什么可以';我不能访问ClientBase的这个公共属性吗?,c#,C#,我有一个名为MyProxyClass的代理类,它是通过围绕SOAP web服务WSDL的svcutil.exe自动生成的。此代理类是抽象System.ServiceModel.ClientBase类的实现: [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] public part

我有一个名为
MyProxyClass
的代理类,它是通过围绕SOAP web服务WSDL的
svcutil.exe
自动生成的。此代理类是抽象
System.ServiceModel.ClientBase
类的实现:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class MyProxyClass : System.ServiceModel.ClientBase<MyProxyClassPortType>, MyProxyClassPortType
{
    // 60,000 lines of auto-generated code
}
但是,当我创建这个代理类的新实例时

var _client = new MyProxyClass();
我无法通过intellisense查看
端点
属性。如果我试图通过
\u client.Endpoint
访问
端点
,编译器会给出相应错误
“MyProxyClass”不包含“Endpoint”的定义,并且找不到接受“MyProxyClass”类型的第一个参数的扩展方法“Endpoint”(是否缺少using指令或程序集引用?

但是,以下反射方法工作正常,返回的属性与我预期的一样:

ServiceEndpoint endpoint = 
(ServiceEndpoint)typeof(ClientBase<MyProxyClassPortType>).GetProperty("Endpoint").GetValue(_client);
ServiceEndpoint=
(ServiceEndpoint)typeof(ClientBase).GetProperty(“端点”).GetValue(_客户端);

那么为什么我不能访问这个公共可访问的(回想一下,
GetProperty
的特定重载只搜索公共属性)属性?

确保将变量键入具体类而不是接口。

如果get为空,则代码将无法编译。能否提供更完整的代码段?是的,但您还想看到什么?您确定要调用的
MyProxyClass
是正确的。您可能有两个在不同的名称空间中使用相同的命名类。(我自己也犯过这样的错误,使用svcutil生成的类,并将代码放在一个部分类中,而不是svcutil生成的名称空间)@ScottChamberlain谢谢,但事实并非如此。这是一个自包含的项目,在解决方案中没有引用其他名称空间。
ServiceEndpoint endpoint = 
(ServiceEndpoint)typeof(ClientBase<MyProxyClassPortType>).GetProperty("Endpoint").GetValue(_client);