Inconsistent Accesibility - WORKS IN VS2003 FAILS in VS 2005

G

Guest

My program compiles correctly in VS 2003 but fails in VS2005 Express Edition
- I get a compile error

Inconsistent accessibility: return type 'VA.Customer' is less accessible
than method 'VA.CustomerDB.GetCustomer(string)'

Here is a snippet

public class CustomerDB
{
public static DataTable GetCustomers()
{
string selectStatement = "SELECT CustomerID, FirstName, LastName "
+ "FROM Customers "
+ "ORDER BY CustomerID";
SqlCommand SelectCommand =
new SqlCommand(selectStatement, GetConnection());
SqlDataAdapter customersDataAdapter =
new SqlDataAdapter(SelectCommand);
DataSet customersDataSet = new DataSet();
customersDataAdapter.Fill(customersDataSet, "Customers");
return customersDataSet.Tables["CustomerID"];
}


public static Customer GetCustomer(string customerID)
{
SqlConnection VAConnection = GetConnection();
string selectStatement = "SELECT CustomerID, FirstName, LastName"
+ "FROM Customers "
+ "WHERE CustomerID = @CustomerID";
SqlCommand selectCommand =
new SqlCommand(selectStatement, VAConnection);
selectCommand.Parameters.Add("@CustomerID", customerID);
SqlDataReader customerReader;
VAConnection.Open();
customerReader =
selectCommand.EndExecuteReader(CommandBehavior.SingleRow);
if (customerReader.Read())
{
Customer customer = new Customer();
customer.CustomerID = (string) customerReader["CustomerID"];
customer.FirstName = (string) customerReader["FirstName"];
customer.LastName = (string) customerReader["LastName"];
VAConnection.Close();
return customer;
}
else
{
VAConnection.Close();
return null;
}
}

The customer class has been defined in a simple format as follows:

class Customer
{
public string CustomerID;
public string FirstName;
public string MiddleName;
public string LastName;

}

Any help would be appreciated - Thanks
 
S

Sherif ElMetainy

Hello

I am surprised you say this code compiles in VS 2003, it shouldn't. I think
you changed something
To solve the problem make the GetCustomer method internal or make the
Customer class public.

Best regards,
Sherif
 
G

Guest

Thanks Sherif - much appreciated. Yes it does compile in VS2003 quirky I
might say.

I made the customer class public and that solved the problem. However, what
are the ramifications for doing that from an architectural point of view?

Regards

Hussein

Sherif ElMetainy said:
Hello

I am surprised you say this code compiles in VS 2003, it shouldn't. I think
you changed something
To solve the problem make the GetCustomer method internal or make the
Customer class public.

Best regards,
Sherif

hodari said:
My program compiles correctly in VS 2003 but fails in VS2005 Express Edition
- I get a compile error

Inconsistent accessibility: return type 'VA.Customer' is less accessible
than method 'VA.CustomerDB.GetCustomer(string)'

Here is a snippet

public class CustomerDB
{
public static DataTable GetCustomers()
{
string selectStatement = "SELECT CustomerID, FirstName, LastName "
+ "FROM Customers "
+ "ORDER BY CustomerID";
SqlCommand SelectCommand =
new SqlCommand(selectStatement, GetConnection());
SqlDataAdapter customersDataAdapter =
new SqlDataAdapter(SelectCommand);
DataSet customersDataSet = new DataSet();
customersDataAdapter.Fill(customersDataSet, "Customers");
return customersDataSet.Tables["CustomerID"];
}


public static Customer GetCustomer(string customerID)
{
SqlConnection VAConnection = GetConnection();
string selectStatement = "SELECT CustomerID, FirstName, LastName"
+ "FROM Customers "
+ "WHERE CustomerID = @CustomerID";
SqlCommand selectCommand =
new SqlCommand(selectStatement, VAConnection);
selectCommand.Parameters.Add("@CustomerID", customerID);
SqlDataReader customerReader;
VAConnection.Open();
customerReader =
selectCommand.EndExecuteReader(CommandBehavior.SingleRow);
if (customerReader.Read())
{
Customer customer = new Customer();
customer.CustomerID = (string) customerReader["CustomerID"];
customer.FirstName = (string) customerReader["FirstName"];
customer.LastName = (string) customerReader["LastName"];
VAConnection.Close();
return customer;
}
else
{
VAConnection.Close();
return null;
}
}

The customer class has been defined in a simple format as follows:

class Customer
{
public string CustomerID;
public string FirstName;
public string MiddleName;
public string LastName;

}

Any help would be appreciated - Thanks
 
S

Sherif ElMetainy

Hello

Making the Customer class public, means that other it can be referenced from
other assemblies. If your project is an exe, in most cases, it doesn't
matter, since assemblies usually reference DLLs. If your project is a DLL
you are making the Customer class visible for other assemblies. This means
that if you release another version of you assembly you cannot rename/remove
the Customer class or any of its public members so that you don't break
assemblies depending on your assembly.

Best regards,
Sherif
hodari said:
Thanks Sherif - much appreciated. Yes it does compile in VS2003 quirky I
might say.

I made the customer class public and that solved the problem. However, what
are the ramifications for doing that from an architectural point of view?

Regards

Hussein

Sherif ElMetainy said:
Hello

I am surprised you say this code compiles in VS 2003, it shouldn't. I think
you changed something
To solve the problem make the GetCustomer method internal or make the
Customer class public.

Best regards,
Sherif

hodari said:
My program compiles correctly in VS 2003 but fails in VS2005 Express Edition
- I get a compile error

Inconsistent accessibility: return type 'VA.Customer' is less accessible
than method 'VA.CustomerDB.GetCustomer(string)'

Here is a snippet

public class CustomerDB
{
public static DataTable GetCustomers()
{
string selectStatement = "SELECT CustomerID, FirstName, LastName "
+ "FROM Customers "
+ "ORDER BY CustomerID";
SqlCommand SelectCommand =
new SqlCommand(selectStatement, GetConnection());
SqlDataAdapter customersDataAdapter =
new SqlDataAdapter(SelectCommand);
DataSet customersDataSet = new DataSet();
customersDataAdapter.Fill(customersDataSet, "Customers");
return customersDataSet.Tables["CustomerID"];
}


public static Customer GetCustomer(string customerID)
{
SqlConnection VAConnection = GetConnection();
string selectStatement = "SELECT CustomerID, FirstName, LastName"
+ "FROM Customers "
+ "WHERE CustomerID = @CustomerID";
SqlCommand selectCommand =
new SqlCommand(selectStatement, VAConnection);
selectCommand.Parameters.Add("@CustomerID", customerID);
SqlDataReader customerReader;
VAConnection.Open();
customerReader =
selectCommand.EndExecuteReader(CommandBehavior.SingleRow);
if (customerReader.Read())
{
Customer customer = new Customer();
customer.CustomerID = (string) customerReader["CustomerID"];
customer.FirstName = (string) customerReader["FirstName"];
customer.LastName = (string) customerReader["LastName"];
VAConnection.Close();
return customer;
}
else
{
VAConnection.Close();
return null;
}
}

The customer class has been defined in a simple format as follows:

class Customer
{
public string CustomerID;
public string FirstName;
public string MiddleName;
public string LastName;

}

Any help would be appreciated - Thanks
 
G

Guest

Thank You Very Much - appreciated

Sherif ElMetainy said:
Hello

Making the Customer class public, means that other it can be referenced from
other assemblies. If your project is an exe, in most cases, it doesn't
matter, since assemblies usually reference DLLs. If your project is a DLL
you are making the Customer class visible for other assemblies. This means
that if you release another version of you assembly you cannot rename/remove
the Customer class or any of its public members so that you don't break
assemblies depending on your assembly.

Best regards,
Sherif
hodari said:
Thanks Sherif - much appreciated. Yes it does compile in VS2003 quirky I
might say.

I made the customer class public and that solved the problem. However, what
are the ramifications for doing that from an architectural point of view?

Regards

Hussein

Sherif ElMetainy said:
Hello

I am surprised you say this code compiles in VS 2003, it shouldn't. I think
you changed something
To solve the problem make the GetCustomer method internal or make the
Customer class public.

Best regards,
Sherif

My program compiles correctly in VS 2003 but fails in VS2005 Express
Edition
- I get a compile error

Inconsistent accessibility: return type 'VA.Customer' is less accessible
than method 'VA.CustomerDB.GetCustomer(string)'

Here is a snippet

public class CustomerDB
{
public static DataTable GetCustomers()
{
string selectStatement = "SELECT CustomerID, FirstName,
LastName "
+ "FROM Customers "
+ "ORDER BY CustomerID";
SqlCommand SelectCommand =
new SqlCommand(selectStatement, GetConnection());
SqlDataAdapter customersDataAdapter =
new SqlDataAdapter(SelectCommand);
DataSet customersDataSet = new DataSet();
customersDataAdapter.Fill(customersDataSet, "Customers");
return customersDataSet.Tables["CustomerID"];
}


public static Customer GetCustomer(string customerID)
{
SqlConnection VAConnection = GetConnection();
string selectStatement = "SELECT CustomerID, FirstName,
LastName"
+ "FROM Customers "
+ "WHERE CustomerID = @CustomerID";
SqlCommand selectCommand =
new SqlCommand(selectStatement, VAConnection);
selectCommand.Parameters.Add("@CustomerID", customerID);
SqlDataReader customerReader;
VAConnection.Open();
customerReader =
selectCommand.EndExecuteReader(CommandBehavior.SingleRow);
if (customerReader.Read())
{
Customer customer = new Customer();
customer.CustomerID = (string)
customerReader["CustomerID"];
customer.FirstName = (string) customerReader["FirstName"];
customer.LastName = (string) customerReader["LastName"];
VAConnection.Close();
return customer;
}
else
{
VAConnection.Close();
return null;
}
}

The customer class has been defined in a simple format as follows:

class Customer
{
public string CustomerID;
public string FirstName;
public string MiddleName;
public string LastName;

}

Any help would be appreciated - Thanks
 
Top