Click here to Skip to main content
15,891,644 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Does the overriding of methods defined in an abstract class differ from a WindowsCE6 app (with .Net2.0 CF) and a Windows App (with .Net2.0 full framework)?

I am having an issue with compiling the same code in the above two platforms (using different project templates in VS2005). Windows app compiles fine without any error, but WinCE app fails with an error: "no suitable method found to override".

Am I missing something?

Any help is appreciated.

Thanks in advance.


[Edited]"Pre" tags removed from normal Sentences[/Edited]
Posted
Updated 23-Jan-11 21:55pm
v2
Comments
[no name] 24-Jan-11 3:55am    
Hard to say, perhaps it will help if you post the declarations of the abstract method and the overriding method.
CPallini 24-Jan-11 4:06am    
Code Watson, we need actual code... :-)
TSKNaidu 25-Jan-11 0:02am    
Please find below the source that generated error:

MoveGraphLibrary.dll:
public abstract bool MoveNode(int i, int dx, int dy, System.Drawing.Point ptM, System.Windows.Forms.MouseButtons catcher) Member of MoveGraphLibrary.GraphicalObject

MyApp.exe:
public abstract class ElementRsRt : GraphicalObject
{
//implements some of the abstract methods in the derived GraphicalObject class
}

public class RingRsRt : ElementRsRt
{
// public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons catcher)
{
//implements the abstract method MoveNode as defined in the grand parent class (GraphicalObject)
}
}

Error occurs while compiling MyApp.exe using .netCF for WinCE. No error while compiling for WinApp.

Thanks for taking time to answer.

[Adding to Kryukov's response.]

.NET CF considerably differs from the regular .NET version (just as how SL for WP7 differs from full Silverlight). It's possible that the CF version does not have this particular method in the base class (not surprising as compact editions are usually far thinner than their full equivalents).
 
Share this answer
 
v2
Comments
TSKNaidu 24-Jan-11 23:54pm    
You are right. Some of the methods in FF are not available in CF. But, we are attempting to implement a derived method in the inherited base class.

As a matter of fact, I commented out the whole code to ensure that the implementing method in question is not using any method from CF/FF. But, we still get this error.

Appreciate your time for addressing this question.

best regards.
Sergey Alexandrovich Kryukov 25-Jan-11 2:07am    
Nishant, you're right about these different versions, but see: MyApp.exe, MoveGraphLibrary.dll -- not a platform GAC, something else.

Anyway, OP does not fully co-operate so far. Another candidate for abandoned question...
[no name] 25-Jan-11 10:27am    
I agree. As I see it, both frameworks may have classes and structs with the same names and methods and possibly even the same implementations. But even if the classes are identical, they will come from different assemblies and are regarded as different types.

I assume the graphics library was built with the regular .Net framework and the parameters (the Point and the MouseButtons) for the abstract method come from the regular framework as well.

The application is built for the compact framework and takes the types for Point and MouseButtons from there. a method can be overloaded only if the parameter types are identical. Here they not, as those two types come from different frameworks, and the method cannot be overidden.
TSKNaidu 25-Jan-11 11:55am    
Thanks CDP for throwing some light!

Though the namespaces and method signatures seem to be the same in both .net CF and FF libraries being used (System.Windows.Forms.dll and System.Drawing.dll in our case), obviously the VS compiler does not see them as same.

Is there a workaround where I can make the compiler do a conditional compilation to use only CF version if a method is supported, else, throw error?

Thanks again for taking time to answer.

best regards.
[no name] 25-Jan-11 12:27pm    
No. The only way would be to compile the graphics library for the compact framework as well (or get such a version). It does not matter how much the signatures look alike. I can compile identical classes in two different assemblies with the same namespace, the same names, the same methods and the same implementation. Just by being in two assemblies they become two separate types for the compiler. If you look at my answer below, you will see that I tried it and got the same error as I predicted. The sources for both classes were identical, letter by letter.
This is the very basics of OOP and C#, does not depend on the platform at all. Rather, you're messing up somewhere. If you're using different template, you could put one of the projects together missing some file (the one with parent class) or a reference.

To sort it out, show fragments of code, both offending and a base class where abstract is, on what exactly line a compilation error points, and the text of your project files.

[EDIT] After a comment by TSKNaidu with the code:

The problem is missing "abstract bool MoveNode" or "virtual boon MoveNode" in any of the base classes up the hierarchy.
You should easily check up this fact on both platform using Visual Studio. Put a cursor on MoveNode and activate context menu, select "Go to Definition", go to base class code (it can be generated from meta-data, which is find), then up to the next base class until you find the abstract or virtual declaration of the method you try to override.
 
Share this answer
 
v2
Comments
TSKNaidu 24-Jan-11 23:46pm    
Please find below the source that generated error:

MoveGraphLibrary.dll:
public abstract bool MoveNode(int i, int dx, int dy, System.Drawing.Point ptM, System.Windows.Forms.MouseButtons catcher)
Member of MoveGraphLibrary.GraphicalObject

MyApp.exe:
public abstract class ElementRsRt : GraphicalObject
{
//implements some of the abstract methods in the derived GraphicalObject class

}

public class RingRsRt : ElementRsRt
{
//
public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons catcher)
{
//implements the abstract method MoveNode as defined in the grand parent class (GraphicalObject)
}
}

Error occurs while compiling MyApp.exe using .netCF for WinCE. No error while compiling for WinApp.

Thanks again for taking time to address my question.

best regards.
Sergey Alexandrovich Kryukov 25-Jan-11 2:04am    
You did not answer my question. You show one class without content + one method without class => Nothing can be seen. Show: class with abstract method (at least two lines) + class with overridden method (at least two more lines).

Switch on light -- it's dark!
Sergey Alexandrovich Kryukov 25-Jan-11 2:06am    
Also show the line pointed by a compilation error...
TSKNaidu 25-Jan-11 12:03pm    
1. Class with abstract method 'MoveNode' is: GraphicalObject (it is in a compiled lib titled 'MoveGraphLibrary.dll').

2. Class with overridden method is: RingRsRt.

3. Error occurs in the overriden method (MoveNode) in the above class.

Thanks for your time.

regards.
Sergey Alexandrovich Kryukov 25-Jan-11 14:12pm    
I see. It looks like a valid source of the compile time error. You see, there is an override of MoveNode in RingRsRt, but there should be either "abstract MoveNode" or "virtual MoveNode" in ElementRsRt or in any of their base classed up the hierarchy. (Unless you simply fail to show this code.) You can easily check up such thing using VS.... wait a minute, I'll put an update in my Answer...
I suspect the problem to come from the two parameters of the types System.Drawing.Point and System.Windows.Forms.MouseButtons.

I assume you use this graphics library as it is and don't recompile it as well. Then it will keep on using the System.Drawing and System.Windows.Forms namespaces of the regular framework. It stays that way when you compile your code for the compact framework. Despite identical namespaces and names, these parameters are not the same and the overload does not work.

The solution? The only thing I can think of is to get this graphics library for the compact framework, if it exists at all.

Edit:
I'm at work right now and can't quickly test my theory, but I'm quite sure that this is what happens here.

EditEdit: I have found the time and whipped together a few test classes to confirm my theory. I got exactly the same error when overriding the abstract method. The params of the method came from two different libraries, playing the role of different frameworks. They had identical namespaces, identical names and identical implementations. But since they came from different frameworks, they were not accepted as the same type and the override failed.,
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900