We help IT Professionals succeed at work.

Class is inaccessible due to its protection level

dba123
dba123 asked
on
2,328 Views
Last Modified: 2008-01-09
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;

            rightToCheck.Add("Delete");

            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
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Top Expert 2007
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
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!

Regards,
Mishu
Anurag ThakurTechnical Manager

Commented:
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
Top Expert 2007

Commented:
So that's three people who have pointed out that they probably needs a public constructor, do you think they are listening?

Author

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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.