Class does not implement inherited abstract member

Posted on 2007-10-12
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?
Question by:dba123
    LVL 96

    Accepted Solution

    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.

    LVL 13

    Expert Comment

    try versioning

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

    Expert Comment

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

    LVL 1

    Author Comment

    I tried that, in fact tried this:

    1            public new bool Authorize(IPrincipal principal, List<string> rightsRequested)
    2            {
    3                bool result = false;
    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");
    8                if (rightsRequested.Count == 1)
    9                {
    10                   dicRights[principal.Identity.Name].Contains(rightsRequested[0]);
    11               }
    13               return result;
    14           }
    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?
    LVL 96

    Expert Comment

    by:Bob Learned
    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.

    LVL 13

    Expert Comment

    "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.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now