?
Solved

Class does not implement inherited abstract member

Posted on 2007-10-12
7
Medium Priority
?
6,833 Views
Last Modified: 2008-07-22
My new derived class inherits from an abstract class.  In the abstract class, it has this method:

        public abstract bool Authorize(IPrincipal principal, string context);

I want to override this method because I want to implement it like this in my derived class:

        public override bool Authorize(IPrincipal principal, List<string> rightsRequested)
       {
            do something
        }

However I get the errors:

'Microsoft.Practices.EnterpriseLibrary.Security.VAuthorizationProvider.Authorize(System.Security.Principal.IPrincipal, System.Collections.Generic.List<string>)': no suitable method found to override

'Microsoft.Practices.EnterpriseLibrary.Security.VAuthorizationProvider' does not implement inherited abstract member 'Microsoft.Practices.EnterpriseLibrary.Security.AuthorizationProvider.Authorize

Where VAuthorizationProvider is my new class that inherits the abstract class AuthorizationProvider.cs

CAn you not override a class in an abstract class?  I would think this would be a common task?
0
Comment
Question by:dba123
  • 3
  • 2
6 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 20065887
You need to match the method signature that you are trying to override, or the compiler cannot find a match, since you can have overloaded methods with different signatures.

Bob
0
 
LVL 13

Expert Comment

by:KarinLoos
ID: 20066222
try versioning

public new bool Authorize(IPrincipal principal, List<string> rightsRequested)
       {
            do something
        }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20066333
Right, that would be shadowing, and not overriding.

Bob
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:dba123
ID: 20066779
I tried that, in fact tried this:

1            public new bool Authorize(IPrincipal principal, List<string> rightsRequested)
2            {
3                bool result = false;
4    
5                if (principal == null) throw new System.ArgumentNullException("IPrincipal is null");
6                if (rightsRequested.Count < 1) throw new System.ArgumentNullException("rightsRequested generic string is null");
7    
8                if (rightsRequested.Count == 1)
9                {
10                   dicRights[principal.Identity.Name].Contains(rightsRequested[0]);
11               }
12  
13               return result;
14           }
15  
16           public bool Authorize(IPrincipal principal, string context)
17           {
18               return false;
19           }

but that doesn't work for me, I get errors:

Errors (what am I doing wrong?):

Error 3 'Microsoft.Practices.EnterpriseLibrary.Security.VAuthorizationProvider' does not implement inherited abstract member 'Microsoft.Practices.EnterpriseLibrary.Security.AuthorizationProvider.Authorize(System.Security.Principal.IPrincipal, string)' C:\EntLib3Src\App Blocks\Src\Security\KUVAuthorizationProvider.cs 15 18 Security

Error 2 Warning as Error: 'Microsoft.Practices.EnterpriseLibrary.Security.VAuthorizationProvider.Authorize(System.Security.Principal.IPrincipal, string)' hides inherited member 'Microsoft.Practices.EnterpriseLibrary.Security.AuthorizationProvider.Authorize(System.Security.Principal.IPrincipal, string)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Error 1 Warning as Error: The member 'Microsoft.Practices.EnterpriseLibrary.Security.VAuthorizationProvider.Authorize(System.Security.Principal.IPrincipal, System.Collections.Generic.List<string>)' does not hide an inherited member. The new keyword is not required.

Ok, I know that I have to satisfy the abstract class by implementing Authorize.  But I want to hide it and use my own Authorize signature (meaning arguments) where I'm passing a generic string and implementing it that way.  So what am I doing wrong here?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20066826
That means that you need to override the method with the exact signature.  It doesn't look like you can define your own method using generics for the arguments.

Bob
0
 
LVL 13

Expert Comment

by:KarinLoos
ID: 20070586
"By default, C# methods are not virtual  if a method is declared as virtual, any class inheriting the method can implement its own version. To make a method virtual, the virtual modifier is used in the method declaration of the base class. The derived class can then override the base virtual method by using the override keyword or hide the virtual method in the base class by using the new keyword. If neither the override keyword nor the new keyword is specified, the compiler will issue a warning and the method in the derived class will hide the method in the base class."

IT would appear that the Authorize method in the base class has not been defined as virtual, thus you cannot provide your own version.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question