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

C

Chip Gore

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
 
C

Chip Gore

[...]
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.
 
C

Chip Gore

[...]
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.
 
B

Ben Voigt [C++ MVP]

Chip said:
[...]
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).
 
P

parez

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..
 
C

Chip Gore

Chip said:
]
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.
 
B

Ben Voigt [C++ MVP]

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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top