"is inaccessible due to its protection level" using a public methodof a public class

Discussion in 'C++' started by Chip Gore, Apr 10, 2008.

  1. Chip Gore

    Chip Gore Guest

    Hi -

    I have some C++ code (functions) that I'm trying to create a C++ class
    for that can be the used as part of a C# project.

    (Very simplified)

    The C# file
    .....................................
    using LightBinding;
    namespace SrvLib
    {
    public class Bosco : MoreBosco
    {
    public static LBind LB;
    public static void InitCache(string connectionString, string user,
    string pswd, int timeout)
    {
    LB.DoConnect(connectionString, user, pswd, timeout);
    }
    #region Things
    public override void StoreItem(CacheItem item)
    {
    bool jnk =
    LB.SaveItem(LB.UseConnect(),item.Key,item.Value,false);
    }
    #endregion //Things
    }
    }
    .....................................
    And the LBind interfaces as seen "from metadata" are
    .....................................
    using System;

    namespace LightBinding
    {
    public class LBind
    {
    public Bosco.LC_Database* LCdbConnection;

    public LBind();

    public void DoConnect(Bosco.d_string* conn, Bosco.d_string* user,
    Bosco.d_string* password, int timeout);
    public bool SaveItem(Bosco.LC_Database* db, sbyte* key, sbyte*
    value, bool verbose);
    public Bosco.LC_Database* UseConnect();
    }
    }
    .....................................

    And I'm getting compile errors for the C# project saying

    'LightBinding.LBind.UseConnect()' is inaccessible due to its
    protection level

    I'm not sure what I need to do to my C++ and/or my C# to make this
    method accessible. There are other public methods in the LBind class
    (SaveItem(),DoConnect(), etc.) that seem to have the visibility and
    the compiler doesn't complain about them.

    "What am I missing?"

    thanks
     
    Chip Gore, Apr 10, 2008
    #1
    1. Advertising

  2. Chip Gore

    Chip Gore Guest

    Re: "is inaccessible due to its protection level" using a publicmethod of a public class

    On Apr 10, 12:28 pm, "Peter Duniho" <>
    wrote:
    > On Thu, 10 Apr 2008 10:06:40 -0700, Chip Gore <>
    > wrote:
    >
    > > [...]
    > > And I'm getting compile errors for the C# project saying

    >
    > > 'LightBinding.LBind.UseConnect()' is inaccessible due to its
    > > protection level

    >
    > > I'm not sure what I need to do to my C++ and/or my C# to make this
    > > method accessible. There are other public methods in the LBind class
    > > (SaveItem(),DoConnect(), etc.) that seem to have the visibility and
    > > the compiler doesn't complain about them.

    >
    > I don't see anything obvious in what you posted. Which means that you
    > didn't post the code that's relevant to your question.
    >
    > You wrote "the LBind interfaces as seen 'from metadata' are", which seems
    > to imply that you didn't actually post the actual code. If there's a
    > protection level problem, then only by seeing the actual code can anyone
    > suggest what might be wrong. Posting some "meta" description of the
    > actual code introduces the possibility of an error in describing the code.
    >
    > We need to know what the code actually is, not what you or some
    > programming tool thinks it is.
    >
    > Pete


    The "Programming Tool" is Visual Studio 2005, when I ask "show
    definition for the call.

    The code is simple enough

    // LightBinding.h
    #pragma once
    using namespace System;
    #include <lc_database.h>
    #include <lc_connection.h>
    #include <CLBAPI.h>
    namespace LightBinding {
    public ref class LBind
    {
    public:
    Bosco::LC_Database *LCdbConnection;

    public:
    LBind() {}
    ~LBind() {}
    bool SaveItem(Bosco::LC_Database *db,const char *key,char
    *value,bool verbose)
    {
    return SaveCacheItem(db,key,value,verbose);
    }
    void DoConnect(Bosco::d_string conn,Bosco::d_string
    user,Bosco::d_string password,int timeout)
    {
    Bosco::Db_err err;
    Bosco::d_string* extname;
    LCdbConnection =
    CreateLightConnection(conn,user,password,timeout,err,extname);
    }
    Bosco::LC_Database * UseConnect()
    {
    return LCdbConnection;
    }
    };
    }

    And the metadata reflects this as an interface.

    All of the function calls used, and data types referred to, are
    encompassed in the include files, and they all work fine, as does this
    C++ class when used in it's own project, the problem is in the C#
    trying to use the C++ stuff.
     
    Chip Gore, Apr 10, 2008
    #2
    1. Advertising

  3. Chip Gore

    Chip Gore Guest

    Re: "is inaccessible due to its protection level" using a publicmethod of a public class

    On Apr 10, 1:59 pm, "Peter Duniho" <>
    wrote:
    > On Thu, 10 Apr 2008 11:40:39 -0700, Chip Gore <>
    > wrote:
    >
    > > [...]
    > > All of the function calls used, and data types referred to, are
    > > encompassed in the include files, and they all work fine,

    >
    > Can you be more specific about "work fine"? In what context?
    >
    > Again, what you posted looks reasonable to me, so if you're getting an
    > error, it's still related to something you didn't post.
    >
    > One wild-ass-guess: what's the protection level of the "d_string" type?
    > Is that type actually visible to the C# code?
    >
    > I suppose one of the interop gurus here (i.e. not me) might be able to
    > figure out the problem just from what you've posted. But you should
    > really consider putting together a concise-but-complete code example that
    > reliably demonstrates the problem. The stuff you've posted so far doesn't
    > seem to have a problem, as near as I can tell.
    >
    > Pete


    Thanks for your effort.
    The code is as concise as I can make considering the NDAs involved.

    If this is not enough information, then I guess I'm SOL.
     
    Chip Gore, Apr 10, 2008
    #3
  4. Re: "is inaccessible due to its protection level" using a public method of a public class

    Chip Gore wrote:
    > On Apr 10, 12:28 pm, "Peter Duniho" <>
    > wrote:
    >> On Thu, 10 Apr 2008 10:06:40 -0700, Chip Gore
    >> <> wrote:
    >>
    >>> [...]
    >>> And I'm getting compile errors for the C# project saying

    >>
    >>> 'LightBinding.LBind.UseConnect()' is inaccessible due to its
    >>> protection level

    >>
    >>> I'm not sure what I need to do to my C++ and/or my C# to make this
    >>> method accessible. There are other public methods in the LBind class
    >>> (SaveItem(),DoConnect(), etc.) that seem to have the visibility and
    >>> the compiler doesn't complain about them.

    >>
    >> I don't see anything obvious in what you posted. Which means that
    >> you didn't post the code that's relevant to your question.
    >>
    >> You wrote "the LBind interfaces as seen 'from metadata' are", which
    >> seems to imply that you didn't actually post the actual code. If
    >> there's a protection level problem, then only by seeing the actual
    >> code can anyone suggest what might be wrong. Posting some "meta"
    >> description of the actual code introduces the possibility of an
    >> error in describing the code.
    >>
    >> We need to know what the code actually is, not what you or some
    >> programming tool thinks it is.
    >>
    >> Pete

    >
    > The "Programming Tool" is Visual Studio 2005, when I ask "show
    > definition for the call.
    >
    > The code is simple enough
    >
    > // LightBinding.h
    > #pragma once
    > using namespace System;
    > #include <lc_database.h>
    > #include <lc_connection.h>
    > #include <CLBAPI.h>
    > namespace LightBinding {
    > public ref class LBind
    > {
    > public:
    > Bosco::LC_Database *LCdbConnection;


    This looks like it should not be public, especially since you provide an
    accessor method.

    >
    > public:
    > LBind() {}
    > ~LBind() {}
    > bool SaveItem(Bosco::LC_Database *db,const char *key,char
    > *value,bool verbose)
    > {
    > return SaveCacheItem(db,key,value,verbose);
    > }
    > void DoConnect(Bosco::d_string conn,Bosco::d_string
    > user,Bosco::d_string password,int timeout)
    > {
    > Bosco::Db_err err;
    > Bosco::d_string* extname;
    > LCdbConnection =
    > CreateLightConnection(conn,user,password,timeout,err,extname);
    > }
    > Bosco::LC_Database * UseConnect()


    What is the declaration for LC_Database? I don't think it will be useable
    from .NET because the * indicates a native type (you can't have normal
    pointers to managed types, only interior_ptr or a tracking handle).

    > {
    > return LCdbConnection;
    > }
    > };
    > }
    >
    > And the metadata reflects this as an interface.
    >
    > All of the function calls used, and data types referred to, are
    > encompassed in the include files, and they all work fine, as does this
    > C++ class when used in it's own project, the problem is in the C#
    > trying to use the C++ stuff.
     
    Ben Voigt [C++ MVP], Apr 10, 2008
    #4
  5. Chip Gore

    parez Guest

    Re: "is inaccessible due to its protection level" using a publicmethod of a public class

    On Apr 10, 1:06 pm, Chip Gore <> wrote:
    > Hi -
    >
    > I have some C++ code (functions) that I'm trying to create a C++ class
    > for that can be the used as part of a C# project.
    >
    > (Very simplified)
    >
    > The C# file
    > ....................................
    > using LightBinding;
    > namespace SrvLib
    > {
    > public class Bosco : MoreBosco
    > {
    > public static LBind LB;
    > public static void InitCache(string connectionString, string user,
    > string pswd, int timeout)
    > {
    > LB.DoConnect(connectionString, user, pswd, timeout);
    > }
    > #region Things
    > public override void StoreItem(CacheItem item)
    > {
    > bool jnk =
    > LB.SaveItem(LB.UseConnect(),item.Key,item.Value,false);
    > }
    > #endregion //Things
    > }}
    >
    > ....................................
    > And the LBind interfaces as seen "from metadata" are
    > ....................................
    > using System;
    >
    > namespace LightBinding
    > {
    > public class LBind
    > {
    > public Bosco.LC_Database* LCdbConnection;
    >
    > public LBind();
    >
    > public void DoConnect(Bosco.d_string* conn, Bosco.d_string* user,
    > Bosco.d_string* password, int timeout);
    > public bool SaveItem(Bosco.LC_Database* db, sbyte* key, sbyte*
    > value, bool verbose);
    > public Bosco.LC_Database* UseConnect();
    > }}
    >
    > ....................................
    >
    > And I'm getting compile errors for the C# project saying
    >
    > 'LightBinding.LBind.UseConnect()' is inaccessible due to its
    > protection level
    >
    > I'm not sure what I need to do to my C++ and/or my C# to make this
    > method accessible. There are other public methods in the LBind class
    > (SaveItem(),DoConnect(), etc.) that seem to have the visibility and
    > the compiler doesn't complain about them.
    >
    > "What am I missing?"
    >
    > thanks


    For which line do you get that error..
     
    parez, Apr 10, 2008
    #5
  6. Chip Gore

    Chip Gore Guest

    Re: "is inaccessible due to its protection level" using a publicmethod of a public class

    On Apr 10, 2:48 pm, "Ben Voigt [C++ MVP]" <> wrote:
    > Chip Gore wrote:
    > > On Apr 10, 12:28 pm, "Peter Duniho" <>
    > > wrote:
    > >> On Thu, 10 Apr 2008 10:06:40 -0700, Chip Gore
    > >> <> wrote:

    >
    > >>> [...]
    > >>> And I'm getting compile errors for the C# project saying

    >
    > >>> 'LightBinding.LBind.UseConnect()' is inaccessible due to its
    > >>> protection level

    >
    > >>> I'm not sure what I need to do to my C++ and/or my C# to make this
    > >>> method accessible. There are other public methods in the LBind class
    > >>> (SaveItem(),DoConnect(), etc.) that seem to have the visibility and
    > >>> the compiler doesn't complain about them.

    >
    > >> I don't see anything obvious in what you posted. Which means that
    > >> you didn't post the code that's relevant to your question.

    >
    > >> You wrote "the LBind interfaces as seen 'from metadata' are", which
    > >> seems to imply that you didn't actually post the actual code. If
    > >> there's a protection level problem, then only by seeing the actual
    > >> code can anyone suggest what might be wrong. Posting some "meta"
    > >> description of the actual code introduces the possibility of an
    > >> error in describing the code.

    >
    > >> We need to know what the code actually is, not what you or some
    > >> programming tool thinks it is.

    >
    > >> Pete

    >
    > > The "Programming Tool" is Visual Studio 2005, when I ask "show
    > > definition for the call.

    >
    > > The code is simple enough

    >
    > > // LightBinding.h
    > > #pragma once
    > > using namespace System;
    > > #include <lc_database.h>
    > > #include <lc_connection.h>
    > > #include <CLBAPI.h>
    > > namespace LightBinding {
    > > public ref class LBind
    > > {
    > > public:
    > > Bosco::LC_Database *LCdbConnection;

    >
    > This looks like it should not be public, especially since you provide an
    > accessor method.
    >
    >
    >
    >
    >
    > > public:
    > > LBind() {}
    > > ~LBind() {}
    > > bool SaveItem(Bosco::LC_Database *db,const char *key,char
    > > *value,bool verbose)
    > > {
    > > return SaveCacheItem(db,key,value,verbose);
    > > }
    > > void DoConnect(Bosco::d_string conn,Bosco::d_string
    > > user,Bosco::d_string password,int timeout)
    > > {
    > > Bosco::Db_err err;
    > > Bosco::d_string* extname;
    > > LCdbConnection =
    > > CreateLightConnection(conn,user,password,timeout,err,extname);
    > > }
    > > Bosco::LC_Database * UseConnect()

    >
    > What is the declaration for LC_Database? I don't think it will be useable
    > from .NET because the * indicates a native type (you can't have normal
    > pointers to managed types, only interior_ptr or a tracking handle).
    >
    > > {
    > > return LCdbConnection;
    > > }
    > > };
    > > }

    >
    > > And the metadata reflects this as an interface.

    >
    > > All of the function calls used, and data types referred to, are
    > > encompassed in the include files, and they all work fine, as does this
    > > C++ class when used in it's own project, the problem is in the C#
    > > trying to use the C++ stuff.


    Hi -

    It turns out that is is the exposure of this pointer that was causing
    the problem.
    I ended up having to code around passing the pointer out and expecting
    it back (I guess I'm still use to machines just doing what I tell them
    to do, when I say "hold this for me", they shouldn't question my
    intentions ;-) )

    Thanks to all who have responded.
     
    Chip Gore, Apr 10, 2008
    #6
  7. Re: "is inaccessible due to its protection level" using a public method of a public class

    > Hi -
    >
    > It turns out that is is the exposure of this pointer that was causing
    > the problem.
    > I ended up having to code around passing the pointer out and expecting
    > it back (I guess I'm still use to machines just doing what I tell them
    > to do, when I say "hold this for me", they shouldn't question my
    > intentions ;-) )


    If you mean "hold this pointer for me", try using
    IntPtr iptr = new IntPtr(ptr);
    and later
    ptr = (NativePtr*)iptr.ToPointer();

    >
    > Thanks to all who have responded.
     
    Ben Voigt [C++ MVP], Apr 10, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,403
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    603
    SpamProof
    Oct 21, 2003
  3. Arjen
    Replies:
    1
    Views:
    5,084
    Arjen
    Jun 11, 2005
  4. sck10
    Replies:
    2
    Views:
    36,425
    sck10
    Aug 28, 2006
  5. Walter Wang [MSFT]
    Replies:
    2
    Views:
    1,278
    Walter Wang [MSFT]
    Jan 19, 2007
Loading...

Share This Page