It looks like a bug in the documentation. If you look at both TcpChannel &
HttpChannel with ILDASM, you'll see that they both implement the ChannelName
property of the IChannel interface, but don't mark their implementations virtual
(which is why you get the compiler error you do).
Since ChannelName is a member of the IChannel interface that channel's
implement, you can work around this using explicit interface implementation:
public class MyChannel : TcpChannel, IChannel
{
string IChannel.ChannelName
{
get { return("MyChannel"); }
}
}
Keep in mind that the above will 'work' as long as everyone is referencing your
custom channel using the IChannel interface type. For example, the remoting
runtime itself uses IChannel to talk to any channels. But if you've got code
written to use "TcpChannel" variables that you end up using to refer to your
custom channel, they'll see the "tcp" channel name, and not yours.
For example, this code:
IChannel ch = new MyChannel();
Console.WriteLine(ch.ChannelName);
will display "MyChannel". But this code:
TcpChannel ch = new MyChannel();
Console.WriteLine(ch.ChannelName);
will display "tcp".
In the former case, the "ch" variable is of type IChannel, so the compiler
generates a late bound call to the ChannelName property getter - resulting in
your implementation of ChannelName being called. But in the latter case, the
"ch" variable is of type "TcpChannel". And since the ChannelName property of
the TcpChannel class is not declared as virtual, the compiler will generate an
early-bound all to the property getter, resulting in a call to
TcpChannel.get_ChannelName, not MyChannel.get_ChannelName.
So just make sure everyone's using IChannel like the runtime does and you'll be
okay.
-Mike
DevelopMentor
http://staff.develop.com/woodring
>
> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of Wayne Citrin
> Sent: Friday, July 11, 2003 12:06 PM
> To: [EMAIL PROTECTED]
>
> I'm trying to create a new Channel that subclasses
> TcpChannel. According
> to the MSDN documentation, TcpChannel.ChannelName is virtual
> and can be
> overridden, but when I try to redeclare ChannelName as
> "override" in my
> new class, it says I can't do it because TcpChannel.ChannelName is not
> new, virtual, or override. Is this a bug?
>
> Thanks for your assistance.
>
> Wayne
>