Re: using protected methods in compact framework

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Please send a small reproducible sample.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Tommy wrote:
For some reason when i tried using derived classes on the .net compact framework it crashes.. is der a reason for this? no exception has come up or anything its simply crashes when it tries to connect.

Thanks and regards

Thomas Engerer

"Sergey Bogdanov" wrote:


Well, Client is a private property and can not be accessed from derived class. However, you can use reflection to achieve what you want:

System.Reflection.FieldInfo fi = typeof(TcpClient).GetField("Client",
	System.Reflection.BindingFlags.NonPublic | 	
	System.Reflection.BindingFlags.Instance);
Socket s = (Socket)fi.GetValue(this);
return ((IPEndPoint)s.LocalEndPoint).ToString();

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Tommy wrote:

I have managed to use the protected methods in the .net framework.. however i need to use the protected method ".Client". so as to get the local endpoint of the current connected socket.

this is the code

public class MyderivedTcpClient : TcpClient
{
// Constructor for the derived class.
public MyderivedTcpClient() : base ()
{
}

public String getAddress()
{
// Calls the protected 'Client' property belonging to the TcpClient base class.
Socket s = this.Client;
return ((IPEndPoint)s.LocalEndPoint).ToString();
}


	}

What solution could you suggest??

Thanks and regards

Thomas Engerer


.



Relevant Pages

  • Re: Vista Media Center Crash
    ... Either the component that raises this event is not installed on your local computer or the installation is corrupted. ... P4: unknown ... it immediately crashes and sends a ...
    (microsoft.public.windows.mediacenter)
  • Re: Windows Services
    ... so u mean to say that i can accept a socket and receive messages but i cant ... > While it's possible to enable this option for quick and dirty debugging, ... >> Multithreaded Server monitoring a Port Number and if any informations come ... >> with regards, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: No Internet Explorer 7 downloads and crashes unless ran as administrator
    ... >>> switch for plugins. ... >>> Regards ... > downloads and many crashes. ...
    (microsoft.public.windows.vista.general)
  • Re: error creating/writing to log file...strange problem!
    ... it crashes on the second line. ... >> opening the app, and problem doesnt appear anymore. ...
    (microsoft.public.pocketpc.developer)
  • Exception setting SocketOption
    ... Dim EP As System.Net.IPEndPoint = New System.Net.IPEndPoint ... I tried also ReceiveTimeOut and with a TCP Socket but it always crashes. ... THX Milosz ...
    (microsoft.public.dotnet.languages.vb)