Why does my method declaration generate an inconsistent accessibility error?
Date : March 29 2020, 07:55 AM
will help you MyListDB type needs to be declared as public. Your method is public and hence the type it returns needs to be public as well (if it wasn't, how else would you access it from anywhere?).
|
Inconsistent Accessibility: Parameter type is less accessible than method error
Tag : chash , By : johntynan
Date : March 29 2020, 07:55 AM
it should still fix some issue If BanjoState is an enum, I have made some assumptions about the rest of your code and added comments to show what is wrong: namespace BanjoStore
{
class Program
{
static void Main(string[] args)
{
//Create a Banjo!
var myFirstBanjo = new Banjo("it's my first!", 4, 67, Banjo.BanjoState.Used);
//Oh no! The above line didn't work because I can't access BanjoState!
//I can't used the enum to pass in the value because it's private to the
//Banjo class. THAT is why the error was visible in the constructor.
//Visual Studio knew this would happen!
}
}
class Banjo
{
//These are private by default since there isn't a keyword specified
//and they're inside a class:
string description;
int price;
//This is also private, with the access typed in front so I don't forget:
private int banjoID;
//This enum is private, but it SHOULD be:
//public enum BanjoState
//Even better, it can be internal if only used in this assembly
enum BanjoState
{
Used,
New
}
public Banjo(string inDescription, int inPrice, int inBanjoID,
BanjoState inState)
{
description = inDescription;
price = inPrice;
banjoID = inBanjoID;
BanjoState state = inState;
}
}
}
class BanjoState //This class is internal, not public!
{
// Methods, properties, fields, events, delegates
// and nested classes go here.
}
|
Error 1 Inconsistent accessibility: return type is less accessible than method
Tag : chash , By : Antony Briggs
Date : March 29 2020, 07:55 AM
wish helps you Your Composite class is not public. You can't return a non-public type from a public method. If you don't specify an accessibility for a non-nested class then internal is used by default. Add public to your Composite class definition: public class Composite
{
...
private Composite buildComposite(ComboBox subs, ComboBox bas)
{
....
|
Inconsistent accessibility error: parameter is less accessible than method
Tag : chash , By : Piotr Balas
Date : March 29 2020, 07:55 AM
I hope this helps you . Your ModBoxUpdateInfoForm constructor is public and requires a parameter of type ModBoxUpdateXml which is internal. You get this exception because a caller outside of your assembly couldn't call the public ModBoxUpdateInfoForm constructor, because the caller is not allowed to have knowledge of what a ModBoxUpdateXml is. Either make ModBoxUpdateXml public, or make the ModBoxUpdateInfoForm constructor internal. internal class A{}
public class B
{
public B(A a){}
}
//Make this public
public class A{}
public class B
{
public B(A a){}
}
internal class A{}
//Make this internal
internal class B
{
public B(A a){}
}
internal class A{}
public class B
{
//Make only the constructor internal
internal B(A a){}
}
|
Why am I obtaining this inconsistent accessibility error on the return type of a method?
Tag : chash , By : protagonist
Date : March 29 2020, 07:55 AM
seems to work fine Your method is public but Inoltro is internal. You cannot have a public method that exposes an internal type. Either make the method internal or the type public. While we are looking at your code, a few things come to mind. using (SqlConnection con = ArxeiaConnection.getARXEIAStringConnection(config.Tenant + "_" + config.Database))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlConnection con = ArxeiaConnection.getARXEIAStringConnection(config.Tenant + "_" + config.Database))
using (SqlCommand cmd = new SqlCommand(query, con))
{
|