views:

262

answers:

2

I tried upgrading an ASP.Net application from Visual Studio 2005 to 2008, and I tried compiling just to verify that it would compile and I received this error.

Error   1 Inconsistent accessibility: property type 'Web.Properties.UITitleSettings' is less accessible than property 'Web.Ctrl.BasePanel.UISettings' \\projectLocation\Ctrl\BasePanel.cs 25 43 ProjectName

(I removed the class path before Web.Properties and Web.Ctrl, it normally contains it)

The piece of code its referencing is

public Properties.UITitleSettings UISettings
    {
        get
        {
            return _uiSettings;
        }
    }

I'm not quite sure what this error is attempting to say. Does the type need to be casted (invalid implicit cast between two incompatible types?) or is it a class override issue?

A: 

Removing the "class path" won't do anything. You're just making your code less verbose... Check the definition of Properties.UITitleSettings. It'll be private or protected etc.

Paul Sasik
I just removed it for privacy reasons more than debugging reasons (just wanted to make clear that its normally contained).The definition of Properties.UITitleSettings is internal sealed partial
tearman
+4  A: 

Look at the following definition. Notice Foo is visible to anyone, and its public method GetBar is also visible to anyone who can see Foo:

public class Foo
{
    public Bar GetBar() { return new Bar(); }
}

Here's the definition of Bar:

internal class Bar {}

Notice Bar is internal to the assembly, whereas Foo is visible to all. Foo cannot expose Bar to the outside world, so the compiler throws this exception.

Another example would be:

public class Foo
{
    public Foo.Bar GetBar() { return new Bar(); }
    private class Bar {}
}

Bar is a private class of Foo and can only be visible to instances of Foo. Foo cannot expose this type to the outside world, so the compiler throws the same exception.


Examples of refactoring:
1) Make the hidden type public

public class Bar {}
public class Foo { public class Bar {} }

2) Encapsulation

public class BarEncapsulator
{
  private Bar _bar;
  internal BarEncapsulator(Bar myBar) { _bar = myBar; }
  public string BarString { get { return _bar.MyString; } }
}

3) Hide everything

internal class Bar {}
internal class Foo { public class Bar {} }

4) Refactor it away

public class BarEncapsulator
{
  private string _barString;
  public string BarString { get { return _barString; } }
}
Will
+1 Nice example.
Philip Wallace
Oh ok, now I get what the error is all about. Now a lot of this code looks like its been generated by the Visual Studio WYSIWYG editor, how would I go about fixing that?
tearman
Whatever you're trying to do in that public accessor is probably wrong. You need to refactor UITitleSettings to either 1) make it a public type 2) encapsulate it in a public type 3) make everything internal or 4) refactor UITitleSettings out of the picture and expose its individual parts as properties delivering primitives (standard system types). Lots of ways to do it; just pick one that isn't how you're doing it now.
Will
Alright, I think that works. It seems as if this is a cascade situation so we'll just have to work through all the resulting issues. Thanks much
tearman