I get the following error when I pass a parameter of the type System.Collections.Generic.List (i.e. List
Error 1 Inconsistent accessibility: parameter type 'System.Collections.Generic.ListThe fix was easy - I just changed the access modifier of the constructor to internal. But I don't understand why that happens, and how the fix makes it work. Trial and error won the day, but I would like to understand what was going on.' is less accessible than method 'CustomerWeightTracker.Report.Report(System.Collections.Generic.List )' D:\bigAl\CustomerWeightTracker\CustomerWeightTracker\Report.cs 16 16 CustomerWeightTracker
Note, it only happens with the generic list. Other types were fine (e.g. ints, user-defined objects etc).
I'd love to get an understanding here.
Thanks
DavePosted Dec 23, 2007, 7:15 AM
You are totally 100% right! I did not read the error message carefully enough.
You were corrent in assuming that the Client class is not a form. And it is the type which I used with the generic list. And it defaulted to internal. Therefore, the list had that inherent restriction.
Thanks very much for helping me get on top of that. It was bugging me. I have now made the Client class public and changed the Report form's constructor back to public. Works fine.
Ace!!!
AlanPosted Dec 23, 2007, 5:49 AM
Hi Dave,
It's the Client class (which I didn't think would be a form) that I thought might be internal. In other words, your set up would be something like this:
namespace CustomerWeightTracker clients)
{
public partial class Report : Form
{
public Report(List
{
//.....
}
//.....
}
class Client // not declared public so internal by default
{
//.....
}
}
Although the generic List class itself is public, its 'effective' accessibility is that of its type argument. So if the type argument is internal then so too is the List.
However, a public constructor or method must have parameters which are themselves public, otherwise it would not be possible to call it from outside the assembly in which it is declared.
To be honest, I can't think of any other possible explanation here.
DavePosted Dec 22, 2007, 7:57 PM
All forms that I create default to public e.g. public partial class Report : Form
The main form frmMain in the app is public. It definitely has something to do with the generic datatype. All other datatypes (that I have tested) do not have this issue.
Cheers
AlanPosted Dec 22, 2007, 8:21 AM
My guess is that the CustomerWeightTracker.Client class is internal which is the default accessibility for classes.
Consequently, the compiler is complaining because you're using an internal type parameter to specify the parameter type of a public constructor.
If I'm right about this, then making the CustomerWeightTracker.Client class public would also have solved the problem.