Click here to Skip to main content
15,891,778 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
i created wcf services in this service method i called class as a perameter.
here iam getting error "Inconsistent accessibility: parameter type '' is less accessible than method"

the code is like below

C#
namespace demo.TransferObjects
{
    public class Severity
    {
        public string LayerName { get; set; }
        public float AttValue { get; set; }
        public float LimitValue { get; set; }
        public float ExpCost { get; set; }
        public float AttachProb { get; set; }
        public float LossProb { get; set; }
        public float ShareLayer { get; set; }
        public float Premium { get; set; }
    }
}


the service declaration i called the severity class as a perameter

C#
[ServiceContract]
    public interface IDemoService
    {
        [OperationContract]
        [WebInvoke(
            Method = "POST",
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json,
            UriTemplate = "/SeverityAnalysis")]
        SeverityResponse SeverityAnalysis(Severity input);

  }

the implementation method also i am getting same issue.
the implemenation method like below

SQL
public class DemoService : IDemoService
    {

        public SeverityResponse SeverityAnalysis(Severity input)
        {
            return ServiceHelper.InvokeList<SeverityResponse, Severity>(() =>
            {
                // Calculate severity based on input values
                return new Severity();

            });
        }

    }
}


please share any information to me.
Posted
Comments
Sergey Alexandrovich Kryukov 4-May-15 10:43am    
In what line?
—SA

1 solution

You did not provide full information in the problem, did not show exact line where the error message refers to, and, quite apparently, did not show the definition of the problematic parameter type. I know that because all types you shown are public, so they cannot possibly done more accessible. It's very likely that you made more members public that it is really required. The problematic type may or may not be SeverityResponse; I don't know exactly because you did not provide enough information.

Next time, make sure you provide comprehensive information. The lines referred by some error message should be commented as such, and such comments should be referenced in the question text. All the relevant code should be shown, but not the "real" code of your project, which could be too big. You need to develop minimal project through extreme simplification of your project code, to make the code suitable for showing in your question. In this case, it would take about 10 lines of code.

In this case, you don't need the code, but you have to understand the principle. It's so simple that you were supposed to understand it just through logical thinking. There can be many similar cases; I'll try to explain the principle on the case of public.

Suppose you declare some method as public. It means that is should be accessible to all code, including the code in another assembly. That said, the declaring method should also be declared public, otherwise the method would remain unacceptable in another assembly. Now, suppose this method has parameters. In fact, it does not matter of the problematic parameter is the generic parameter, or just the method parameter. Imagine that this is the class or struct declared in the same assembly as internal, which is, by the way, the case when you omit the type access specifier, leave the access to default. Now, imagine what happens when you actually use the method in another assembly. Despite the public, it could not be used because one of the parameters is not accessible. Therefore, you have to make the parameter type also public.

Apply similar considerations for other cases when choosing access specifiers. Start from learning their meaning and purpose.

—SA
 
Share this answer
 

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