0

Structure Definition

[StructLayout(LayoutKind.Sequential, Pack = Compile.PackSize)]
  unsafe struct DB_PREPLIST
  {
    public TxnUnion txn;
    public fixed byte gid[DbConst.DB_XIDDATASIZE];
  }

Inaccessible error

enter image description here

Question

When I try to change the DB_PREPLIST as public I get another error:

Pointers and Fixed size buffers may only be used in an unsafe context

Community
  • 1
  • 1
Pankaj
  • 9,749
  • 32
  • 139
  • 283

2 Answers2

2

All methods that need DB_PREPLIST as arguments need to be private in your code. Making DB_PREPLIST public would technically work, but is bad style, as you would need to mark all call sites unsafe. Better wrap all calls with another pure C# structure as argument and make your Delegate private. In this particular scenario, this will probably mean that you'll have to redirect the calls to the delegate through the wrapper, too.

PMF
  • 14,535
  • 3
  • 23
  • 49
0

This reply by Tony The Lion answers your question: Basically, you need to wrap the code calling the unsafe struct in an 'unsafe' block, i.e.

unsafe 
{
   //your code
}

(edit) you also need to add the public access modifier onto your struct, otherwise, unsafe or not, you won't be able to access it (unless it's nested in the class which calls it).

Community
  • 1
  • 1
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • 1
    I think that's the wrong way to go. Marking such a structure public is usually not desirable. – PMF Jan 13 '14 at 09:02