2

I get an error message in VisualStudio that I can't solve on my own. The message is:

Inconsistent accesibility: property type 'WindowsFormApplication1.ContactFiles.Contact' is less accessible than property 'WindowsFormApplication1.ContactForm.ContactData'

public ContactFiles.Contact ContactData { get { return m_contact; } set { if (value != null) m_contact = value; } } 

Preciate help to find the error source for this problem! Thanks!

3 Answers 3

5

Mark ContactFiles.Contact as public to resolve the error.

Your public property ContactData is returning a an instance of the non-public type ContactFiles.Contact.

Sign up to request clarification or add additional context in comments.

1 Comment

When I did that, I got several new error messages, like the first one!?
2

Kyle has suggested one approach, but if that's causing more (similar) errors then you could try going the other way: make your property internal:

internal ContactFiles.Contact ContactData { // Code as before } 

If you need the property to be public, then you'll need Contact to be public... which means you need to look at all the public properties of Contact to see whether they refer to internal (or private) types, etc.

Basically you can't have a public property returning an internal (or private nested) type - it would be effectively saying "You can use this, but you're not allowed to know anything about what I'll return" which doesn't make sense. The same is true for parameters and return types of normal methods. You also can't derive a public class from an internal one.

3 Comments

When I changed to internal instead of public, I don't get the error message any more! Great! But I'm not really sure how it all works. I'm not using any derived classes.
@3D-kreativ: I only mentioned derived classes at the end. Do you understand that your Contact class wasn't public, but you were trying to expose it via a public property? Do you understand what accessibility (public, internal, private etc) is about? Then consider that it doesn't make sense for a public method to return or require an internal type - and that's basically what your property was doing.
Hmm, I guess I know what you are trying to explane, it takes some time to get in to my head
0

This exception occures when u try to return a internal or private object in method which is public available. The same exception occures if you try to give a private-known objecte to a public-method

2 Comments

It's not an exception, and it's not an internal or private object - it's the type.
Oh sorry. i meant type. And yes it's no exceptions it's a compiler-error

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.