• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2246
  • Last Modified:

Class is inaccessible due to its protection level

Ok, I have created this class:

using System.Security.Principal;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Security.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Security.Instrumentation;
using Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation;
using System.Collections.Generic;

namespace Microsoft.Practices.EnterpriseLibrary.Security
    /// <summary>
    /// implementation of the <see cref="IVAuthorizationProvider"/> interface.
    /// </summary>
    public class VAuthorizationProvider : IVAuthorizationProvider, IInstrumentationEventProvider
        AuthorizationProviderInstrumentationProvider instrumentationProvider;
.. rest of class members here

In a console project, in a class I created in order to test a method call for that class I tried to create the console test like this:

namespace TestSandBox
    class VAuthorizationProviderTesting
        static void Main(string[] args)
            List<string> rightToCheck = null;


            VAuthorizationProvider provider = new VAuthorizationProvider();
            IPrincipal principal = new GenericPrincipal(new GenericIdentity("Don"), new string[] { "Manager" });

            provider.Authorize(principal, rightToCheck);

For the line VAuthorizationProvider provider = new VAuthorizationProvider();

I get the error "Microsoft.Practices.EnterpriseLibrary.Security.VAuthorizationProvider.VAuthorizationProvider()' is inaccessible due to its protection level
2 Solutions
Gautham JanardhanCommented:
can u give the construcotrs of VAuthorizationProvider
Do yoyu have a public constructor?
Mihai StancescuSoftware Engineer Commented:
You must have the main constructor of that class public, should be something like this:

public VAuthorizationProvider()
 //...constructor login here

Hope this helps!

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.

Anurag ThakurCommented:
The error can come when you can not create member of the class i.e. the default constructor (as in this case) is private
private VAuthorizationProvider ()
or it is protected

Hope this helps
So that's three people who have pointed out that they probably needs a public constructor, do you think they are listening?
dba123Author Commented:
nah, I decided to be cool and use a protected.  Ah!  thanks.  Ok, so I had copied code from another abstract class.  Why did I do this, cause I was assigned in my group to create a custom AuthorizationProvider.cs.  Well, I wasn't sure how so I created a new class, copied the code and then tweaked it to make it "custom" in my n ew class as well as created a new interface.  I guess I coul dhave just inherited the initial abstract class in my new class.   Not sure which way to go.

So since I had pasted the code, the constructor was protected.  I see now.  Thanks.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now