Home c# Cannot calculate the size unmanaged via Marshal.sizeof structure in C #

Cannot calculate the size unmanaged via Marshal.sizeof structure in C #

Author

Date

Category

There is some structure converted from C in C #, as the library (DLL) is written on C, but it is necessary to use it in the project on C #.

Here is the code code on C #:

[Structlayout (layoutkind.sequential, charset = charset.ansi)]
#Pragma Warning Disable IDE1006 // Naming Styles
Public Struct RTKSVR_T.
#Pragma Warning Restore Ide1006 // Naming Styles
{
/ * RTK Server Type * /
  Public int state; / * Server State (0: Stop, 1: Running) * /
  Public int Cycle; / * Processing Cycle (MS) * /
  Public int nMeacycle; / * NMEA Request Cycle (MS) (0: NO REQ) * /
  Public int nmeareq; / * NMEA Request (0: No, 1: NMEAPOS, 2: Single Sol) * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public Double [] nmeapos; / * NMEA Request Position (ECEF) (M) * /
  Public int buffsize; / * INPUT BUFFER SIZE (bytes) * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public int [] Format; / * INPUT FORMAT {ROV, BASE, CORR} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 2)]
  Public Solopt_t [] solopt; / * Output Solution Options {Sol1, Sol2} * /
  Public int navsel; / * EPHEMERIS SELECT (0: ALL, 1: ROVER, 2: BASE, 3: CORR) * /
  Public int NSBS; / * Number of Sbas Message * /
  Public int nsol; / * Number of Solution Buffer * /
  Public RTK_T RTK; / * RTK Control / Result Struct * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public int [] nb; / * BYTES IN INPUT BUFFERS {ROV, BASE} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 2)]
  Public int [] nsb; / * Bytes in soulution Buffers * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public int [] NPB; / * BYTES IN INPUT PEEK BUFFERS * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public Byte [] buff; / * INPUT BUFFERS {ROV, BASE, CORR} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 2)]
  Public Byte [] SBUF; / * Output Buffers {Sol1, Sol2} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public Byte [] PBUF; / * Peek Buffers {ROV, BASE, CORR} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSOLBUF)]
  Public Sol_t [] Solbuf; / * Solution Buffer * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3 * 10)]
  Public int [] nmsg; / * INPUT MESSAGE COUNTS * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public Raw_t [] Raw; / * Receiver Raw Control {ROV, BASE, CORR} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public RTCM_T [] RTCM; / * RTCM Control {ROV, BASE, CORR} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public gtime_t [] ftime; / * Download Time {ROV, Base, Corr} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3 * MAXSTRPATH)]
  Public Char [] Files; / * Download Paths {ROV, Base, Corr} * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3 * MAXOBSBUF)]
  Public OBS_T OBS; / * observation data {rov, base, corr} * /
  Public Nav_t NAV; / * Navigation Data * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSBSMSG)]
  Public SBSMSG_T SBSMSG; / * Sbas Message Buffer * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 8)]
  public stream_t stream; / * Streams {ROV, BASE, CORR, SOL1, SOL2, LOGR, LOGB, LOGC} * /
  Public Intptr MONI; / * monitor stream * /
  Public Uint Tick; / * Start Tick * /
  Public Intptr Thread; / * Server Thread * /
  Public int CPutime; / * CPU Time (MS) for a Processing Cycle * /
  Public int PrCout; / * Missing OBSERVATION DATA COUNT * /
  Public int nave; / * Number of Averaging Base POS * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3)]
  Public Double [] RB_Ave; / * Averaging Base POS * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 3 * MAXRCVCMD)]
  Public Char [] cmds_periodic; / * Periodic Commands * /
  [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXRCVCMD)]
  Public Char [] cmd_reset; / * RESET COMMAND * /
  Public Double Bl_reset; / * Baseline Length to Reset (KM) * /
  Public Critical_SECTION Lock_Flag; / * Lock Flag * /
};

Original structure on C:

typeedef struct {/ * RTK Server Type * /
  int state; / * Server State (0: Stop, 1: Running) * /
  int Cycle; / * Processing Cycle (MS) * /
  int nmeacycle; / * NMEA Request Cycle (MS) (0: NO REQ) * /
  INT NMEAREQ; / * NMEA Request (0: No, 1: NMEAPOS, 2: Single Sol) * /
  Double NMeapos [3]; / * NMEA Request Position (ECEF) (M) * /
  int buffsize; / * INPUT BUFFER SIZE (bytes) * /
  int format [3]; / * INPUT FORMAT {ROV, BASE, CORR} * /
  SOLOPT_T SOLOPT [2]; / * Output Solution Options {Sol1, Sol2} * /
  INT NAVSEL; / * EPHEMERIS SELECT (0: ALL, 1: ROVER, 2: BASE, 3: CORR) * /
  INT NSBS; / * Number of Sbas Message * /
  int nsol; / * Number of Solution Buffer * /
  RTK_T RTK; / * RTK Control / Result Struct * /
  INT NB [3]; / * BYTES IN INPUT BUFFERS {ROV, BASE} * /
  INT NSB [2]; / * Bytes in soulution Buffers * /
  INT NPB [3]; / * BYTES IN INPUT PEEK BUFFERS * /
  unsigned char * buff [3]; / * INPUT BUFFERS {ROV, BASE, CORR} * /
  unsigned char * sbuf [2]; / * Output Buffers {Sol1, Sol2} * /
  unsigned char * pbuf [3]; / * Peek Buffers {ROV, BASE, CORR} * /
  SOL_T SOLBUF [MAXSOLBUF]; / * Solution Buffer * /
  unsigned int nmsg [3] [10]; / * INPUT MESSAGE COUNTS * /
  RAW_T RAW [3]; / * Receiver Raw Control {ROV, BASE, CORR} * /
  rtcm_t rtcm [3]; / * RTCM Control {ROV, BASE, CORR} * /
  gtime_t ftime [3]; / * Download Time {ROV, Base, Corr} * /
  Char Files [3] [MaxStrPath]; / * Download Paths {ROV, Base, Corr} * /
  OBS_T OBS [3] [MAXOBSBUF]; / * observation data {rov, base, corr} * /
  nav_t nav; / * Navigation Data * /
  SBSMSG_T SBSMSG [MAXSBSMSG]; / * Sbas Message Buffer * /
  stream_t stream [8]; / * Streams {ROV, BASE, CORR, SOL1, SOL2, LOGR, LOGB, LOGC} * /
  stream_t * moni; / * monitor stream * /
  unsigned int tick; / * Start Tick * /
  thread_t thread; / * Server Thread * /
  INT CPUTIME; / * CPU Time (MS) for a Processing Cycle * /
  int prcout; / * Missing OBSERVATION DATA COUNT * /
  INT NAVE; / * Number of Averaging Base POS * /
  Double RB_AVE [3]; / * Averaging Base POS * /
  char cmds_periodic [3] [maxrcvcmd]; / * Periodic Commands * /
  char cmd_reset [maxrcvcmd]; / * RESET COMMAND * /
  Double BL_RESET; / * Baseline Length to Reset (KM) * /
  lock_t lock; / * Lock Flag * /
} RTKSVR_T;

In C # I am trying to initialize this structure:

datartk.rtksvr_t rtksvr;
Int Isizertksrv;
INTPTR RTKSRV_PTR;
Try.
{
  isizertksrv = marshal.sizeof (Typeof (datartk.rtksvr_t));
}
Catch (ArgumentException EX)
{
  STRING STRERR = EX.MESSAGE;
}
Catch (TypeLoadException EX)
{
  STRING STRERR = EX.MESSAGE;
}
Try.
{
  RTKSRV_PTR = Marshal.Alloccotaskmem (Isizertksrv);
}
Catch (ArgumentException EX)
{
  STRING STRERR = EX.MESSAGE;
}
Datartk.rtksvr_t RTKSRV = (Marshal.ptrtostructure (RTKSRV_PTR, TYPEOF (DatartK.Rtksvr_t)));

When trying to find out the size issues the System.ArgumentException error with the following post:

type ‘realtimemonitor.datartk + RTKSVR_T’ CANNOT BE MARSHALED AS AN
UNMANAGED STRUCTURE; No Meaningful Size Or Offset Can Be Computed.

From useful can be stack:

at system.runtime.interopservices.marshal.sizeofhelper (Type T, Boolean ThrowifnotMarshalable)
at system.runtime.interopservices.marshal.sizeof (Type T)
At RealtimeMonitor.StreamHub. & LT; WriteItems & GT; D__139.MoveNext () In C: \ Users \ Zharkov.v \ Source \ Repos \ RealtimeMonitor \ ReiltimeMonitor \ StreamHub.cs: Line 138

I understand that it cannot create an object, but still I can not understand what’s the matter or can I go wrong. No memory is also issued an error that is not enough memory, so I rewrote to this option.

Who can tell me what I do wrong?

updated 12.02.2020

[strellayout (layoutkind.sequential, charset = charset.ansi)] 
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct RTK_T.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
          / * RTK Control / Result Type * /
      Public Sol_t Sol; / * RTK Solution * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 6)]
      Public Double [] RB; / * Base Position / Velocity (ECEF) (M | M / S) * /
      Public int nx, na; / * Number of Float States / Fixed States * /
      Public Double TT; / * Time Difference Between Current and Previous (S) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public Double [] x, p; / * Float States and their Covariance * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public Double [] XA, PA; / * Fixed States and their Covariance * /
      Public int nfix; / * Number of Continuous Fixes of AMBIGUITY * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public AMBC_T [] AMBC; / * AMBIBUITY CONTROL * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public SSAT_T [] SSAT; / * Satellite Status * /
      Public int NEB; / * BYTES IN ERROR MESSAGE BUFFER * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXERRMSG)]
      Public Char [] ErrBuf; / * Error Message Buffer * /
      Public Prcopt_t OPT; / * Processing Options * /
    };
  [StructlaYout (layoutkind.sequential, charset = charset.ansi)]
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct Solopt_t.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SizeConst = 18)] / * Solution Options Type * /
      Public int POSF; / * Solution Format (Solf _ ???) * /
      Public Int Times; / * TIME SYSTEM (TIMES _ ???) * /
      Public Int Timef; / * Time Format (0: Sssss.s, 1: Yyyy / MM / DD HH: mm: SS.S) * /
      Public Int Timeu; / * Time Digits Under Decimal Point * /
      Public int degf; / * Latitude / Longitude Format (0: DDD.DDD, 1: DDD MM SS) * /
      Public int Outhead; / * Output Header (0: No, 1: Yes) * /
      Public int Outopt; / * Output Processing Options (0: NO, 1: YES) * /
      Public int OutVEL; / * OUTPUT VELOCITY OPTIONS (0: NO, 1: YES) * /
      Public int Datum; / * Datum (0: WGS84.1: Tokyo) * /
      Public int Height; / * Height (0: Ellipsoidal, 1: Geodetic) * /
      Public int Geoid; / * Geoid Model (0: EGM96,1: JGD2000) * /
      Public Int Solstatic; / * Solution of Static Mode (0: All, 1: Single) * /
      Public int SSTAT; / * Solution Statistics Level (0: Off, 1: States, 2: Residuals) * /
      Public int trace; / * Debug Trace LEVEL (0: Off, 1-5: Debug) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 2)]
      Public Double [] nmeaintv; / * NMEA OUTPUT INTERVAL (S) (& lt; 0: no, 0: all) * /
      / * NMeaintV [0]: GPRMC, GPGGA, NMEAINTV [1]: GPGSV * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 64)]
      Public Char [] SEP; / * Field Separator * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 64)]
      Public Char [] Prog; / * Program Name * /
      Public Double MaxSolstd; / * MAX STD-DEV for Solution Output (M) (0: ALL) * /
    };
    [StructlaYout (layoutkind.sequential, charset = charset.ansi)]
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct Sol_t.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
      / * Solution Type * /
      Public GTime_T Time; / * Time (GPST) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 6)]
      Public Double [] RR; / * Position / Velocity (M | M / S) * /
      / * {x, y, z, vx, vy, vz} or {e, n, u, ve, vn, vu} * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 6)]
      Public Float [] QR; / * Position Variance / Covariance (M ^ 2) * /
      / * {C_XX, C_YY, C_ZZ, C_XY, C_YZ, C_ZX} OR * / 
/ * {C_EE, C_NN, C_UU, C_EN, C_NU, C_UE} * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 6)]
      Public Float [] QV; / * VELOCITY VARIANCE / COVARIANCE (M ^ 2 / S ^ 2) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 6)]
      Public Double [] DTR; / * Receiver Clock Bias to Time Systems (S) * /
      Public Byte Type; / * Type (0: XYZ-ECEF, 1: ENU-Baseline) * /
      Public Byte Stat; / * Solution Status (Solq _ ???) * /
      Public Byte NS; / * Number of Valid Satellites * /
      Public Float Age; / * Age of Differential (S) * /
      Public Float Ratio; / * AR Ratio Factor for Valiation * /
      Public Float Thres; / * AR Ratio Threshold for Valiation * /
    };
[StructlaYout (layoutkind.sequential, charset = charset.ansi)]
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct Raw_t.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
          / * Receiver Raw Data Control Type * /
      Public GTime_T Time; / * Message Time * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SizeConst = MaxSat * (NFREQ + NEXOBS))]
      public gtime_t tobs; // [MaxSat * (NFREQ + NEXOBS)]; / * OBSERVATION DATA TIME * /
      Public OBS_T OBS; / * OBSERVATION DATA * /
      Public OBS_T OBUF; / * Observation Data Buffer * /
      Public Nav_t NAV; / * Satellite EPHEMERIDES * /
      Public Sta_T STA; / * Station Parameters * /
      Public int ephsat; / * Sat Number of Update Ephemeris (0: No Satellite) * /
      Public SBSMSG_T SBSMSG; / * Sbas Message * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 256)]
      Public Char [] msgtype; / * Last Message Type * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT * 380)]
      Public Char [] subfrm; / * Subframe Buffer * /
      Public Lexmsg_t Lexmsg; / * Lex Message * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SizeConst = MaxSat * (NFREQ + NEXOBS))]
      Public Double [] Lockt; / * Lock Time (s) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public Double [] ICPP;
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public Double [] OFF;
      Public Double ICPC; / * Carrier Params for ss2 * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public Double [] PRCA;
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public Double [] DPCA; / * L1 / CA PSEUDRANGE / DOPPLER FOR JAVAD * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SizeConst = MaxSat * (NFREQ + NEXOBS))]
      Public Byte [] Halfc; / * Half-Cycle Add Flag * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXOBS)]
      Public Char [] Freqn; / * FREQUENCY NUMBER FOR JAVAD * /
      Public int Nbyte; / * Number of Bytes in Message Buffer * /
      Public int Len; / * Message Length (Bytes) * /
      Public int iod; / * ISSUE OF DATA * /
      Public int Tod; / * Time Of Day (MS) * /
      Public int TBASE; / * Time Base (0: GPST, 1: UTC (USNO), 2: GLONASS, 3: UTC (SU) * /
      Public int flag; / * General Purpose Flag * /
      Public int Outtype; / * OUTPUT MESSAGE TYPE * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXRAWLEN)]
      Public Byte [] buff; / * Message Buffer * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXOBS)]
      Public Char [] OPT; / * Receiver Dependent Options * /
      Public Half_cyc_t Half_Cyc; / * Half-Cycle Correction List * /
      Public int Format; / * Receiver Stream Format * /
      Public intptr rcv_data; / * Receiver Dependent Data * /
    };
 [StructlaYout (layoutkind.sequential, charset = charset.ansi)]
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct RTCM_T.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
      / * RTCM Control Struct Type * /
      Public int staid; / * Station ID * / 
Public int stah; / * Station Health * /
      Public int seqno; / * SEQUENCE NUMBER FOR RTCM 2 OODS MSM * /
      Public int Outtype; / * OUTPUT MESSAGE TYPE * /
      Public GTime_T Time; / * Message Time * /
      Public gtime_t time_s; / * Message Start Time * /
      Public OBS_T OBS; / * observation data (uncorrected) * /
      Public Nav_t NAV; / * Satellite EPHEMERIDES * /
      Public Sta_T STA; / * Station Parameters * /
      Public DGPS_T DGPS; / * Output of DGPS Corrections * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public SSR_T [] SSR; / * Output of SSR Corrections * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 128)]
      Public Char [] MSG; / * Special Message * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 256)]
      Public Char [] msgtype; / * Last Message Type * /
      [Marshalas (Unmanagedtype.byvalarray, SizeConst = 6 * 128)]
      Public Char [] msmtype; / * MSM Signal Types * /
      Public int obsflag; / * OBS Data Complete Flag (1: OK, 0: NOT COMPLETE) * /
      Public int ephsat; / * Update Satellite of Ephemeris * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SizeConst = MaxSat * (NFREQ + NEXOBS))]
      Public Double [] CP; / * Carrier-Phase Measurement * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SizeConst = MaxSat * (NFREQ + NEXOBS))]
      Public short [] Time_Lock; / * Lock Time * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SizeConst = MaxSat * (NFREQ + NEXOBS))]
      Public Short [] Loss; / * Loss of Lock Count * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SizeConst = MaxSat * (NFREQ + NEXOBS))]
      public gtime_t [] lltime; / * Last Lock Time * /
      Public int Nbyte; / * Number of Bytes in Message Buffer * /
      Public int nbit; / * Number of Bits in Word Buffer * /
      Public int Len; / * Message Length (Bytes) * /
      [Marshalas (Unmanagedtype.byvalarray, SizeConst = 1200)]
      Public Byte [] buff; / * Message Buffer * /
      Public Uint Word; / * Word Buffer for RTCM 2 * /
      [Marshalas (Unmanagedtype.byvalarray, SizeConst = 100)]
      Public Uint [] nmsg2; / * Message Count of RTCM 2 (1-99: 1-99.0: Other) * /
      [Marshalas (Unmanagedtype.byvalarray, SizeConst = 400)]
      Public Uint [] nmsg3; / * Message Count of RTCM 3 (1-299: 1001-1299,300-399: 2000-2099.0: OHTER) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 256)]
      Public Char [] OPT; / * RTCM Dependent Options * /
    };
#REGION Structure
    [STRUCTLAYOUT (LAYOUTKIND.SEQUENTIAL, CHARSET = CHARSET.ANSI)] / * TIME STRUCT * /
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct GTime_T.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
      Public Intptr Time; / * (s) ExpRessed by Standard Time_T * /
      Public Double SEC; / * Of Second Under 1 S * /
    }
[STRUCTLAYOUT (Layoutkind.Sequential, Charset = Charset.ansi)] / * observation data * /
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct Obs_t.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
      Public int n, nmax; / * Of Obervation Data / Allocated * /
      Public Obsd_t Data; / * Data Records * /
    }
  [StructlaYout (layoutkind.sequential, charset = charset.ansi)]
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct Nav_T.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
      / * Navigation Data Type * /
      Public int n, nmax; / * Number of Broadcast Ephemeris * /
      Public int ng, ngmax; / * Number of GLONASS EPHEMERIS * /
      Public int ns, nsmax; / * Number of Sbas Ephemeris * /
      Public int NE, NEMAX; / * Number of Precise Ephemeris * /
      Public int nc, ncmax; / * Number of Precise Clock * /
      Public int Na, Namax; / * Number of Almanac Data * / 
Public int NT, NTmax; / * Number of TEC Grid Data * /
      Public int NF, NFMAX; / * Number of Satellite FCB Data * /
      Public Eph_t EPH; / * GPS / QZS / GAL EPHEMERIS * /
      Public GEPH_T Geph; / * GLONASS EPHEMERIS * /
      public seph_t seph; / * SBAS EPHEMERIS * /
      Public Peph_t Peph; / * Precise Ephemeris * /
      Public PCLK_T PCLK; / * Precise Clock * /
      Public alm_t alm; / * ALMANAC DATA * /
      Public Tec_t TEC; / * TEC GRID DATA * /
      Public FCBD_T FCB; / * Satellite FCB Data * /
      Public ERP_T ERP; / * Earth Rotation Parameters * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] UTC_GPS; / * GPS Delta-UTC Parameters {A0, A1, T, W} * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] UTC_GLO; / * GLONASS UTC GPS Time Parameters * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] UTC_GAL; / * Galileo UTC GPS Time Parameters * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public double [] UTC_QZS; / * QZS UTC GPS Time Parameters * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] UTC_CMP; / * Beidou UTC Parameters * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] utc_IRN; / * IRNSS UTC Parameters * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] UTC_SBS; / * SBAS UTC Parameters * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 8)]
      Public Double [] ion_gps; / * GPS Iono Model Parameters {A0, A1, A2, A3, B0, B1, B2, B3} * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] ion_gal; / * Galileo Iono Model Parameters {AI0, AI1, AI2,0} * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] ion_qzs; / * Qzss Iono Model Parameters {A0, A1, A2, A3, B0, B1, B2, B3} * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 8)]
      Public Double [] ion_cmp; / * Beidou Iono Model Parameters {A0, A1, A2, A3, B0, B1, B2, B3} * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 8)]
      Public Double [] ion_IRN; / * Irnss Iono Model Parameters {A0, A1, A2, A3, B0, B1, B2, B3} * /
      Public int Leaps; / * LEAP Seconds (s) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT * NFREQ)]
      Public Double [] LAM; / * Carrier Wave Lengths (M) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT * 3)]
      Public Double [] Cbias; / * Satellite DCB (0: P1-P2,1: P1-C1,2: P2-C2) (M) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXRCV * 2 * 3)]
      Public Double [] Rbias; / * Receiver DCB (0: P1-P2,1: P1-C1,2: P2-C2) (M) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public Double [] Wlbias; / * Wide-Lane Bias (Cycle) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 4)]
      Public Double [] Glo_cpbias; / * GLONASS Code-Phase Bias {1C, 1P, 2C, 2P} (M) * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXPRNGLO + 1)]
      Public Char [] Glo_FCN; / * GLONASS FREQUENCY CHANNEL NUMBER + 8 * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public PCV_T [] PCVS; / * Satellite Antenna PCV * /
      Public SBSSAT_T SBSSAT; / * SBAS Satellite Corrections * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXBAND + 1)]
      Public SBSION_T SBSion; / * SBAS IONOSPHERE CORRECTIONS * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public DGPS_T DGPS; / * DGPS Corrections * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public SSR_T SSR; / * SSR Corrections * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = MAXSAT)]
      Public Lexeph_t Lexeph; / * Lex Ephemeris * /
      Public Lexion_T Lexion; / * Lex IonOSphere Correction * / 
public pppcorr_t pppcorr; / * PPP Corrections * /
    };
[StructlaYout (layoutkind.sequential, charset = charset.ansi)]
#Pragma Warning Disable IDE1006 // Naming Styles
    Public struct sbsmsg_t
#Pragma Warning Restore Ide1006 // Naming Styles
    {
      / * Sbas Message Type * /
      Public int Week, Tow; / * Receiption Time * /
      Public int PRN; / * SBAS SATELLITE PRN NUMBER * /
      [Marshalas (UNMANAGEDTYPE.BYVALARRAY, SIZECONST = 29)]
      Public Byte [] MSG; / * Sbas Message (226Bit) Padded by 0 * /
    };
[StructlaYout (layoutkind.sequential)]
    Public Struct Critical_Section
    {
      Public Intptr Debuginfo;
      Public Int Lockcount;
      Public Int RecursionCount;
      Public intptr owngthread;
      Public Intptr Locksemaphore;
      Public Uintptr Spincount;
    }

It seems everything laid out. If I forgot something add.

updated 12.02.2020 13:28

Many corrected problems, but remained, which I can not decide

Sales on C

typedef struct Half_cyc_tag {/ * Half-Cycle Correction List Type * /
  Unsigned Char Sat; / * SATELLITE NUMBER * /
  Unsigned Char Freq; / * Frequency Number (0: L1.1: L2,2: L5) * /
  Unsigned Char Valid; / * Half-Cycle Valid Flag * /
  Char Corr; / * Half-Cycle Corrected (x 0.5 CYC) * /
  gtime_t ts, te; / * Time Start, Time End * /
  STRUCT HALF_CYC_TAG * NEXT; / * Pointer To Next Correction * /
} half_cyc_t;

implemented on C # so

[Structlayout (layoutkind.sequential, charset = charset.ansi)]
#Pragma Warning Disable IDE1006 // Naming Styles
    Public Struct Half_Cyc_t.
#Pragma Warning Restore Ide1006 // Naming Styles
    {
      [Marshalas (Unmanagedtype.byvalarray, SizeConst = 7)] / * Half-Cycle Correction List Type * /
      Public Byte Sat; / * SATELLITE NUMBER * /
      Public Byte Freq; / * Frequency Number (0: L1.1: L2,2: L5) * /
      Public Byte Valid; / * Half-Cycle Valid Flag * /
      Public Char Corr; / * Half-Cycle Corrected (x 0.5 CYC) * /
      Public gtime_t TS, TE; / * Time Start, Time End * /
      //[Marshalas(unmanagedtype.byvalarray, SizeConst =)]
      Public Unsafe Half_Cyc_t * Next; / * Pointer To Next Correction * /
    };

gives this

Cannot Marshal Field ‘Half_Cyc’ Of Type ‘Raw_t’: The Type Definition
Of this Field Has Layout Information But Has An Invalid
Managed / unmanaged Type Combination or is unmashalable.


Answer 1, Authority 100%

at least, this item looks erroneous:

[Marshalas, SizeConst = 18)] / * Solution Options Type * /
Public int POSF;

Managed type int, and uncontrollable – array?

In addition, you have many other inconsistencies that, although they cannot lead to this error, but because of them the code will not work correctly. For example, in an unmanaged structure:

unsigned char * buff [3];

This is an array of three pointers to bytes

In managed:

[Marshalas (Unmanagedtype.byvalarray, SizeConst = 3)]
Public Byte [] buff;

This is an array of three bytes (values). They are not equivalent. Check all your structures that they correctly use types in accordance with the recommendations MarsHaling Data with Platform Invoke .


Answer 2

did not count the previous answer, as the answer, since it is too common. And he himself has already corrected such mistakes before the response appears. Well, now in order.

error №1
In the Solopt_t structure, we delete the [Marshalas, SizeConst = 18)] line before describing the structure elements.

error number 2
In the structure of exterr_t we replace Public Double Cerr; / * Code Errors (M) * / on Public Double [] Cerr; / * Code Errors (M) * / , since it is worth [MarshalaSA, SizeConst = 4 NFREQ 2)]

error №3
In the structure of Raw_t We replace the GTime Tobs string on GTime [] Tobs – the reason for the same

error №4
In the structure of obsd_t We replace the double L line on double [] l … Well, you already understood)))

error №5
In the structure RAW_T I replace the lexeph_t lexeph string on lexeph_t [] lexeph .

Error №6
In the structure of Raw_t We replace the SBSION_T SBSion line on sbsion_t [] SBSion .

error number 7
The most difficult, I was looking for another place, but it turned out …
Delete a string before starting the description of the [Marshalas, Unmanagedty.byvalarray, SizeConst = 7)]

error number 8
Structure RTKSVR Replace sbsmsg_t sbsmsg on sbsmsg_t [] sbsmsg .

error №9
Structure RTKSVR Replace OBS_T OBS on OBS_T [] OBS .

error number 10
Structure RTKSVR Replace Stream_t OBS on Stream_t [] OBS .

could be counted and the previous answer could be counted, but I corrected these mistakes, which he says, but not corrected that they are not specified in it and about the conformity of the types P / Invoke – not at the wrong side, since it is very I had to reread a lot.

PS Thank you very much to my friends from Pavlodar, Karaganda and especially Taganrog for invaluable assistance in solving this issue and not only.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions