Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Weird "Inconsistent Accessibility" problem

Weird "Inconsistent Accessibility" problem

Scheduled Pinned Locked Moved C#
helpcssquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    realJSOP
    wrote on last edited by
    #1

    I have two classes (of my own creation) that I instantiate in my app.

    public partial class MyForm
    {
    MyObject1 m_myObject1;
    MyObject2 m_myObject2;
    }

    I have another class (ThreadData) that contains objects of those two classes as well (and I use the same names for the variables in this class as I do in the app).

    public class ThreadData
    {
    MyObject1 m_myObject1;
    MyObject2 m_myObject2;
    }

    In a function, I create an instance of ThreadData, and use clones of the app's objects to set the objects in ThreadData. When I try to compile, I get this message:

    error CS0052: Inconsistent accessibility: field type 'MyForm.MyObject1' is less accessible than field 'MyForm.ThreadData.m_myObject1'

    Even if I don't use Clone(), it still gives me the same errors. Why?

    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

    T S 2 Replies Last reply
    0
    • R realJSOP

      I have two classes (of my own creation) that I instantiate in my app.

      public partial class MyForm
      {
      MyObject1 m_myObject1;
      MyObject2 m_myObject2;
      }

      I have another class (ThreadData) that contains objects of those two classes as well (and I use the same names for the variables in this class as I do in the app).

      public class ThreadData
      {
      MyObject1 m_myObject1;
      MyObject2 m_myObject2;
      }

      In a function, I create an instance of ThreadData, and use clones of the app's objects to set the objects in ThreadData. When I try to compile, I get this message:

      error CS0052: Inconsistent accessibility: field type 'MyForm.MyObject1' is less accessible than field 'MyForm.ThreadData.m_myObject1'

      Even if I don't use Clone(), it still gives me the same errors. Why?

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      T Offline
      T Offline
      tgrt
      wrote on last edited by
      #2

      What's the accessibility on your MyObject1 type? m_myObject1 is public, so basically MyObject1 has to be the same.

      R 1 Reply Last reply
      0
      • R realJSOP

        I have two classes (of my own creation) that I instantiate in my app.

        public partial class MyForm
        {
        MyObject1 m_myObject1;
        MyObject2 m_myObject2;
        }

        I have another class (ThreadData) that contains objects of those two classes as well (and I use the same names for the variables in this class as I do in the app).

        public class ThreadData
        {
        MyObject1 m_myObject1;
        MyObject2 m_myObject2;
        }

        In a function, I create an instance of ThreadData, and use clones of the app's objects to set the objects in ThreadData. When I try to compile, I get this message:

        error CS0052: Inconsistent accessibility: field type 'MyForm.MyObject1' is less accessible than field 'MyForm.ThreadData.m_myObject1'

        Even if I don't use Clone(), it still gives me the same errors. Why?

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        It basically means that m_myObject1 is accessible, but its type, MyObject1, is not. Something like

        internal class B
        {

        }

        public class A
        {
        public B b;
        }

        In the example above, A.b is public, but the class B is not.

        Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

        1 Reply Last reply
        0
        • T tgrt

          What's the accessibility on your MyObject1 type? m_myObject1 is public, so basically MyObject1 has to be the same.

          R Offline
          R Offline
          realJSOP
          wrote on last edited by
          #4

          Here's a better example of what I'm doing.

          public class MyObject1 {}

          public class MyObject2 {}

          public class MyData
          {
          public MyObject1 myObj1;
          public MyObject2 myObj2;

          public SetData(MyObject1 ojb1, MyObject2 obj2)
          {
              myObj1 = obj1;
              myObj2 = obj2;
          }
          

          }

          public partial class MyForm
          {
          private MyObject1 myObj1;
          private MyObject2 myObj2;

          private void MyFunction()
          {
              MyData data = new MyData();
              data.SetData(myObj1, myObj2);
          }
          

          }

          That should be perfectly okay.

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          A 1 Reply Last reply
          0
          • R realJSOP

            Here's a better example of what I'm doing.

            public class MyObject1 {}

            public class MyObject2 {}

            public class MyData
            {
            public MyObject1 myObj1;
            public MyObject2 myObj2;

            public SetData(MyObject1 ojb1, MyObject2 obj2)
            {
                myObj1 = obj1;
                myObj2 = obj2;
            }
            

            }

            public partial class MyForm
            {
            private MyObject1 myObj1;
            private MyObject2 myObj2;

            private void MyFunction()
            {
                MyData data = new MyData();
                data.SetData(myObj1, myObj2);
            }
            

            }

            That should be perfectly okay.

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            A Offline
            A Offline
            AndrewVos
            wrote on last edited by
            #5

            That compiles for me. Is that the exact code?


            www.wickedorange.com www.andrewvos.com

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups