473,770 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interface re-implementation changed from 1.0 to 2.0???

Something has changed from C# 1.0 to 2.0 regarding interface
re-implementation. See my sample code below; when compiled and run under VS
2003, you get:

Control.Paint
Control.IContro l.Paint

But when compiled and run under VS 2005: you get:

Control.Paint
Control.Paint

Please explain why in C# 2.0, a class that re-implements an interface
prefers to map to a virtual method of the base class rather than an explicit
implementation of the base class.

Thanks
----
using System;

namespace InterfaceMapTes t
{
class MyApp
{
static void Main(string[] args)
{
MyControl obj = new MyControl();
obj.Paint();

IControl iControl = obj as IControl;
iControl.Paint( );
}
}

public interface IControl
{
void Paint();
}

class Control : IControl
{
public virtual void Paint()
{
Console.WriteLi ne("Control.Pai nt");
}

void IControl.Paint( )
{
Console.WriteLi ne("Control.ICo ntrol.Paint");
}
}

class MyControl : Control, IControl
{
}
}
Aug 31 '06 #1
20 1615
Verified ... quite weird.
"Andy DeMaurice" <an******@noema il.nospamwrote in message
news:04******** *************** ***********@mic rosoft.com...
Something has changed from C# 1.0 to 2.0 regarding interface
re-implementation. See my sample code below; when compiled and run under
VS
2003, you get:

Control.Paint
Control.IContro l.Paint

But when compiled and run under VS 2005: you get:

Control.Paint
Control.Paint

Please explain why in C# 2.0, a class that re-implements an interface
prefers to map to a virtual method of the base class rather than an
explicit
implementation of the base class.

Thanks
----
using System;

namespace InterfaceMapTes t
{
class MyApp
{
static void Main(string[] args)
{
MyControl obj = new MyControl();
obj.Paint();

IControl iControl = obj as IControl;
iControl.Paint( );
}
}

public interface IControl
{
void Paint();
}

class Control : IControl
{
public virtual void Paint()
{
Console.WriteLi ne("Control.Pai nt");
}

void IControl.Paint( )
{
Console.WriteLi ne("Control.ICo ntrol.Paint");
}
}

class MyControl : Control, IControl
{
}
}


Aug 31 '06 #2
OK ..

I checked through the spec and couldn't find anything on a quick read
through specifying this had changed so I escalated it to another list.
Should hear something back soon.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Andy DeMaurice" <an******@noema il.nospamwrote in message
news:04******** *************** ***********@mic rosoft.com...
Something has changed from C# 1.0 to 2.0 regarding interface
re-implementation. See my sample code below; when compiled and run under
VS
2003, you get:

Control.Paint
Control.IContro l.Paint

But when compiled and run under VS 2005: you get:

Control.Paint
Control.Paint

Please explain why in C# 2.0, a class that re-implements an interface
prefers to map to a virtual method of the base class rather than an
explicit
implementation of the base class.

Thanks
----
using System;

namespace InterfaceMapTes t
{
class MyApp
{
static void Main(string[] args)
{
MyControl obj = new MyControl();
obj.Paint();

IControl iControl = obj as IControl;
iControl.Paint( );
}
}

public interface IControl
{
void Paint();
}

class Control : IControl
{
public virtual void Paint()
{
Console.WriteLi ne("Control.Pai nt");
}

void IControl.Paint( )
{
Console.WriteLi ne("Control.ICo ntrol.Paint");
}
}

class MyControl : Control, IControl
{
}
}


Aug 31 '06 #3
OK I think I know what is happenning but I am awaiting confirmation.

I think when you re-implement the interface on MyControl it is seeing the
Paint() method on the base and implementing the interface with it. I have
not been able to find the area of the spec that would define this behavior
but I believe this is the cause of the issue. I will continue digging
through the spec based upon this and let you know if I can come up with
something but immediately you can work around it by not re-implementing the
interface on the derived class which will give the same behavior (except it
works)

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Greg Young" <dr************ *******@hotmail .comwrote in message
news:uP******** ******@TK2MSFTN GP05.phx.gbl...
OK ..

I checked through the spec and couldn't find anything on a quick read
through specifying this had changed so I escalated it to another list.
Should hear something back soon.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Andy DeMaurice" <an******@noema il.nospamwrote in message
news:04******** *************** ***********@mic rosoft.com...
>Something has changed from C# 1.0 to 2.0 regarding interface
re-implementation. See my sample code below; when compiled and run under
VS
2003, you get:

Control.Pain t
Control.IContr ol.Paint

But when compiled and run under VS 2005: you get:

Control.Pain t
Control.Pain t

Please explain why in C# 2.0, a class that re-implements an interface
prefers to map to a virtual method of the base class rather than an
explicit
implementati on of the base class.

Thanks
----
using System;

namespace InterfaceMapTes t
{
class MyApp
{
static void Main(string[] args)
{
MyControl obj = new MyControl();
obj.Paint();

IControl iControl = obj as IControl;
iControl.Paint( );
}
}

public interface IControl
{
void Paint();
}

class Control : IControl
{
public virtual void Paint()
{
Console.WriteLi ne("Control.Pai nt");
}

void IControl.Paint( )
{
Console.WriteLi ne("Control.ICo ntrol.Paint");
}
}

class MyControl : Control, IControl
{
}
}



Aug 31 '06 #4
Hi Andredem,

Yes, this is really a strange issue. Based on my research, I find that the
C# compiled generated IL is almost the same with VS.net2003 and VS2005:

VS.net2003:
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] InterfaceMapTes t.MyControl obj,
[1] InterfaceMapTes t.IControl iControl)
L_0000: newobj instance void InterfaceMapTes t.MyControl::.c tor()
L_0005: stloc.0
L_0006: ldloc.0
L_0007: callvirt instance void InterfaceMapTes t.Control::Pain t()
L_000c: ldloc.0
L_000d: stloc.1
L_000e: ldloc.1
L_000f: callvirt instance void InterfaceMapTes t.IControl::Pai nt()
L_0014: ret
}

VS2005
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] InterfaceMapTes t.MyControl obj,
[1] InterfaceMapTes t.IControl iControl)
L_0000: nop
L_0001: newobj instance void InterfaceMapTes t.MyControl::.c tor()
L_0006: stloc.0
L_0007: ldloc.0
L_0008: callvirt instance void InterfaceMapTes t.Control::Pain t()
L_000d: nop
L_000e: ldloc.0
L_000f: stloc.1
L_0010: ldloc.1
L_0011: callvirt instance void InterfaceMapTes t.IControl::Pai nt()
L_0016: nop
L_0017: ret
}
As we can see that, .Net2.0 generated IL code emits 1 or 2 more nop
instruction, which does not interrupt the code logic. So the problem should
lie in runtime changes regarding interface reimplementatio n between 1.1 and
2.0 CLR.

I have forwarded this issue to our C# team, I will feedback any progress
here. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 1 '06 #5
Jeffrey, I have validated this as a runtime issue. The problem is not
present in later versions of the runtime with the same IL.

I have forwarded it off in hopes of reaching the CLR team.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

""Jeffrey Tan[MSFT]"" <je***@online.m icrosoft.comwro te in message
news:I7******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Andredem,

Yes, this is really a strange issue. Based on my research, I find that the
C# compiled generated IL is almost the same with VS.net2003 and VS2005:

VS.net2003:
method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] InterfaceMapTes t.MyControl obj,
[1] InterfaceMapTes t.IControl iControl)
L_0000: newobj instance void InterfaceMapTes t.MyControl::.c tor()
L_0005: stloc.0
L_0006: ldloc.0
L_0007: callvirt instance void InterfaceMapTes t.Control::Pain t()
L_000c: ldloc.0
L_000d: stloc.1
L_000e: ldloc.1
L_000f: callvirt instance void InterfaceMapTes t.IControl::Pai nt()
L_0014: ret
}

VS2005
method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] InterfaceMapTes t.MyControl obj,
[1] InterfaceMapTes t.IControl iControl)
L_0000: nop
L_0001: newobj instance void InterfaceMapTes t.MyControl::.c tor()
L_0006: stloc.0
L_0007: ldloc.0
L_0008: callvirt instance void InterfaceMapTes t.Control::Pain t()
L_000d: nop
L_000e: ldloc.0
L_000f: stloc.1
L_0010: ldloc.1
L_0011: callvirt instance void InterfaceMapTes t.IControl::Pai nt()
L_0016: nop
L_0017: ret
}
As we can see that, .Net2.0 generated IL code emits 1 or 2 more nop
instruction, which does not interrupt the code logic. So the problem
should
lie in runtime changes regarding interface reimplementatio n between 1.1
and
2.0 CLR.

I have forwarded this issue to our C# team, I will feedback any progress
here. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 1 '06 #6
Greg,

So are you saying this is a bug? If it's not then I can't imagine why
it would have been changed.

Brian

Greg Young wrote:
Jeffrey, I have validated this as a runtime issue. The problem is not
present in later versions of the runtime with the same IL.

I have forwarded it off in hopes of reaching the CLR team.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
Sep 2 '06 #7
I am saying I am not sure but it appears so.

It seems to work differently with the same IL ILASM'ed in 2.0.50727.97 and
2.0.50727.42

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Brian Gideon" <br*********@ya hoo.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Greg,

So are you saying this is a bug? If it's not then I can't imagine why
it would have been changed.

Brian

Greg Young wrote:
>Jeffrey, I have validated this as a runtime issue. The problem is not
present in later versions of the runtime with the same IL.

I have forwarded it off in hopes of reaching the CLR team.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Sep 2 '06 #8
You can also just use the .97 revision of the CLR ... not much help if you
are distributing this app to many users but there is a download for it.

Cheers,

Greg
"Greg Young" <dr************ *******@hotmail .comwrote in message
news:%2******** **********@TK2M SFTNGP04.phx.gb l...
>I am saying I am not sure but it appears so.

It seems to work differently with the same IL ILASM'ed in 2.0.50727.97 and
2.0.50727.42

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Brian Gideon" <br*********@ya hoo.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
>Greg,

So are you saying this is a bug? If it's not then I can't imagine why
it would have been changed.

Brian

Greg Young wrote:
>>Jeffrey, I have validated this as a runtime issue. The problem is not
present in later versions of the runtime with the same IL.

I have forwarded it off in hopes of reaching the CLR team.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung


Sep 2 '06 #9
More information
http://codebetter.com/blogs/gregyoun...0-runtime.aspx

I believe it is a bug but has been fixed in revision 97.

Cheers,

Greg

"Brian Gideon" <br*********@ya hoo.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Greg,

So are you saying this is a bug? If it's not then I can't imagine why
it would have been changed.

Brian

Greg Young wrote:
>Jeffrey, I have validated this as a runtime issue. The problem is not
present in later versions of the runtime with the same IL.

I have forwarded it off in hopes of reaching the CLR team.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Sep 2 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8204
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by making my contnent dlls implement an interface created in vb6. The viewer application is bound to this interface. This way, I am able to add Content without redeploying the dlls (I just have to add the new dlls). I want to write new content for...
3
3370
by: Davide M3xican Coppola | last post by:
Hi, I would realize an interface (interface) for a pair of concrete classes (concrete & concrete2), but I have a problem because I have to access to a third class (element) and if I try to declare interface class as friend, I obtain this (right) error: main2.cpp: In member function `virtual void concrete::method(element&)': main2.cpp:8: error: `int element::a_int' is protected main2.cpp:31: error: within this context
1
8505
by: Microsoft | last post by:
Hello there, I have following situation , how can I solve this puzzle in C#. I have interface called IVendor with some custom attributes applied to it interface IVendor {
6
5199
by: Donal McWeeney | last post by:
I was under the impression that in an interface declaration I could inherit another interface declaration and the result would be that the inheriting interface could include the methods and properties defined in the inherited interface. However when playing with this and defining a class to implement the interface the class gets implemented with both sets of interface declarations. eg.
4
2109
by: christopher diggins | last post by:
A feature that I find signficantly missing in C# is the ability to write functions in interfaces that can call other functions of the interface. Given an interface ISomeInteface the only way we can write a general purpose function to operate on all objects which implement that interface is through the following style of declaration (in the following code snippets i is an interface variable of type ISomeInterface) : SomeStaticClass {...
3
4142
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability. The User Experience, or how the user experiences the end product, is the key to acceptance. And that is where User Interface Design enters the design process. While product engineers focus on the technology, usability specialists focus on the user...
6
12001
by: Sgt. Sausage | last post by:
I know it's not possible, but I need a protected internal interface: protected internal interface ISomeInterface{ // yadda yadda yadda } Basically, I need an interface that is completely accessable from within the assembly (internal), but is not valid outside
2
4990
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators "," variable-declarator variable-declarator:
0
1075
by: Scott James | last post by:
This seems like a strange one, but perhaps someone can shed some light. I have an interface: ItciEngine implemented by class tciEngine. Two public methods in this class pass an object I've created: uiMessage: Public Function TesterInteract(ByVal luiMessage As IuiMessage) As IuiMessage Implements ItciEngine.TesterInteract
0
986
by: Eric | last post by:
I'm trying to create a single interafce that can be implelment by either a ..Net class or a COM object. Here's what I'm tried to do. I defined an interface using VB.net in an assembly all by itself. This interface has a couple of simple procedures and 3 events. I created a test project in VB.Net to test a class implementing the interface and everything works fine. I'm now trying to get a COM object to implement this interface. I used...
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.