Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:56:49+00:00 2026-05-26T02:56:49+00:00

I am stuck with one issue that I have not been able to solve

  • 0

I am stuck with one issue that I have not been able to solve for two days.

The error message looks as below:

Cannot take the address of, get the size of, or declare a pointer to a managed type
(‘Control_Vertilon.Imports.PHOTONIQ_CONFIG_TABLE’)

Below is the code,

         UInt16[] Arguments = new UInt16[PHOTONIQ_ARG_BUFF_SZ];

         PHOTONIQ_CONFIG_TABLE PhotoniqConfigTable = new PHOTONIQ_CONFIG_TABLE();

        UInt16 *cfgPtr = (UInt16*)&PhotoniqConfigTable;       

        for(int i = 0; i < Imports.CONFIG_TABLE_SZ; i++){
            Arguments[i+1] =  *cfgPtr++; 
        }

        Imports.ControlInterface(Opcode, Arguments, 0x1, Imports.TimeoutMs, ref errInNoErrorStruct, ref NumRetArguments, ref PhotoniqConfigTable, Imports.CONFIG_TABLE_SZ, ref errOutStruct);   

where the PhotoniqConfigTable which I marshaled looks as below,

       [StructLayout(LayoutKind.Sequential)]
        unsafe public struct PHOTONIQ_CONFIG_TABLE
        {
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SystemMode;       //Indicates current system mode, acquire or standby mode 0 = Standby Mode 1 = Acquire Mode
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVLimit0;   // Maximum allowed voltage on HV supply 1 Range = 500 ?9250 (50 ?925V)
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVLimit1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 NumChannelsB0;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 NumChannelsB1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 NumChannelsB2;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 NumChannelsB3;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVEnabled;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVSetpoint0;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVSetpoint1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 UserConfigID;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 DCRD_AOut_0;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 BandEnables;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band0StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band0StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band1StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band1StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band2StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band2StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band3StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band3StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band4StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band4StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band5StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band5StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band6StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band6StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band7StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band7StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 FlagEnables;      // pterm flag enables
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] Flag0Operands;  // flag 0 operands: 64 bits
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] Flag1Operands;  // flag 0 operands: 64 bits
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] Flag2Operands;  // flag 0 operands: 64 bits
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] Flag3Operands;  // flag 0 operands: 64 bits
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] Flag4Operands;  // flag 0 operands: 64 bits
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] Flag5Operands;  // flag 0 operands: 64 bits
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] Flag6Operands;  // flag 0 operands: 64 bits
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] Flag7Operands;  // flag 0 operands: 64 bits
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm0;               // flag 0 - 7 product terms
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm2;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm3;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm4;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm5;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm6;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm7;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 DataFilterEnable; // 1 = enable spectral filtering, 0 = disable
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 ProcessingEnables;    // bit 0 = spect filt, bit 1 = gain, 2 = bkgnd sub.
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 TimestampEnable;  // 1 = enable time stamp, 0 = disable
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 DACspare;
            [MarshalAs(UnmanagedType.I4)]
            public Int32 TimestampInterval; //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 CustomWordsEnable;    // 1/0
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 EventCustomCount; //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 RESERVED;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 ImageAcqMode;     // 1 = image, 0 = particle
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 InputTrigThresh;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 InputTrigChannel; // 
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 RangeErrorEnable; // 1 = enable range error, 0 = disable
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 CrossBankConfig;  //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 ReportPackingMode;    //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 GPOutputEnable;       //
            [MarshalAs(UnmanagedType.I4)]
            public Int32 GPOutputDelay;     //
            [MarshalAs(UnmanagedType.I4)]
            public Int32 GPOutputPeriod;        //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 IntBoxcarEnable;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 BoxcarWidthEnable;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public Int32[] ResetDelay;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] TrigSource;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public Int32[] TrigPeriod;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public Int32[] IntegPeriod;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public Int32[] IntegDelay;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel0;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel2;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel3;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel4;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel5;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel6;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel7;
            [MarshalAs(UnmanagedType.I4)]
            public Int32 TriggerEndCount;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 TrigStampSelect;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public UInt16[] DataFormat;     // 4 banks: 0 = 17bit sign/mag, 1 = 16bit 2's, comp, 2 = 16b, 2's 1/2 scale
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 7)]
            public UInt16[] RESERVED1;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256)]
            public UInt16[] GainArray;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256)]
            public UInt16[] TrigThreshArray;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 16)]
            public UInt16[] TrigEnableArray;    // 256 bits, 1/0 for each channel (max of 256 channels)
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 322)]
            public UInt16[] RESERVED2;          //  678-999
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 250)]
            public UInt16[] CustomArray;            // user custom space: 1000-1249
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 567)]
            public UInt16[] FactoryArray;           // start of factory table
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 32)]
            public SByte[] ModelNumber;         // model number
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 151)]
            public UInt16[] FactoryArray1;      // last piece of factory table
        }  

The problem is, I thought I made the structure unmanaged type yet compiler saying it is managed type.

Or it could be that the UInt16 pointer pointing such way is wrong in managed code.

The buffer Argument[] is in 16bit and that’s the passing argument in the dll function so I have stick with 16bit whether using as pointer or buffer to move data.

It would be a tremendous help if anybody can help how to solve this problem.

I have searched web yet could not find precise answer.

Thanks in advance.

==================================================================================

Hi thanks for the reply,

Here I receive different errors with code below:

        fixed (UInt16 *cfgPtr = (UInt16*)&PhotoniqConfigTable){
            //modify config table, then send it back up to PhotoniQ
            PhotoniqConfigTable.NumChannelsB0 = 6;
            PhotoniqConfigTable.IntegPeriod[0] = per;
            PhotoniqConfigTable.TrigPeriod[0] = 100000;
            PhotoniqConfigTable.TrigStampSelect = 1;
            PhotoniqConfigTable.TimestampEnable = 0;
            PhotoniqConfigTable.RangeErrorEnable = 0;
            PhotoniqConfigTable.DataFormat[0] = 0;
            PhotoniqConfigTable.GPOutputEnable = 1;
            PhotoniqConfigTable.GPOutputDelay = 10;
            PhotoniqConfigTable.GPOutputPeriod = 1000;

            for (int i = 0; i < Imports.CONFIG_TABLE_SZ; i++)
            {
                Arguments[i + 1] = *cfgPtr++;
            }
        }      

The error messages are:

Cannot assign to ‘cfgPtr’ because it is a ‘fixed variable’.

The right hand side of a fixed statement assignment may not be a cast expression.

You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement. (Three same errors for different lines)

anybody who can explain to me will be great help since I am in short of time.

The structure now looks as below:

        [StructLayout(LayoutKind.Sequential)]
        unsafe public struct PHOTONIQ_CONFIG_TABLE
        {
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SystemMode;       //Indicates current system mode, acquire or standby mode 0 = Standby Mode 1 = Acquire Mode
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVLimit0;   // Maximum allowed voltage on HV supply 1 Range = 500 ?9250 (50 ?925V)
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVLimit1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 NumChannelsB0;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 NumChannelsB1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 NumChannelsB2;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 NumChannelsB3;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVEnabled;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVSetpoint0;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 HVSetpoint1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 UserConfigID;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 DCRD_AOut_0;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 BandEnables;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band0StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band0StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band1StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band1StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band2StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band2StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band3StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band3StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band4StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band4StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band5StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band5StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band6StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band6StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band7StartIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 Band7StopIndex;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 FlagEnables;      // pterm flag enables
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 Flag0Operands[4];   // flag 0 operands: 64 bits
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 Flag1Operands[4];   // flag 0 operands: 64 bits
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 Flag2Operands[4];   // flag 0 operands: 64 bits
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 Flag3Operands[4];   // flag 0 operands: 64 bits
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 Flag4Operands[4];   // flag 0 operands: 64 bits
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 Flag5Operands[4];   // flag 0 operands: 64 bits
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 Flag6Operands[4];   // flag 0 operands: 64 bits
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 Flag7Operands[4];   // flag 0 operands: 64 bits
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm0;               // flag 0 - 7 product terms
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm2;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm3;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm4;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm5;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm6;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 PTerm7;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 DataFilterEnable; // 1 = enable spectral filtering, 0 = disable
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 ProcessingEnables;    // bit 0 = spect filt, bit 1 = gain, 2 = bkgnd sub.
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 TimestampEnable;  // 1 = enable time stamp, 0 = disable
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 DACspare;
            [MarshalAs(UnmanagedType.I4)]
            public Int32 TimestampInterval; //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 CustomWordsEnable;    // 1/0
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 EventCustomCount; //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 RESERVED;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 ImageAcqMode;     // 1 = image, 0 = particle
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 InputTrigThresh;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 InputTrigChannel; // 
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 RangeErrorEnable; // 1 = enable range error, 0 = disable
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 CrossBankConfig;  //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 ReportPackingMode;    //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 GPOutputEnable;       //
            [MarshalAs(UnmanagedType.I4)]
            public Int32 GPOutputDelay;     //
            [MarshalAs(UnmanagedType.I4)]
            public Int32 GPOutputPeriod;        //
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 IntBoxcarEnable;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 BoxcarWidthEnable;
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed Int32 ResetDelay[4];
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 TrigSource[4];
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed Int32 TrigPeriod[4];
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed Int32 IntegPeriod[4];
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed Int32 IntegDelay[4];
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel0;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel1;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel2;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel3;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel4;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel5;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel6;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 SibSel7;
            [MarshalAs(UnmanagedType.I4)]
            public Int32 TriggerEndCount;
            [MarshalAs(UnmanagedType.U2)]
            public UInt16 TrigStampSelect;
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public fixed UInt16 DataFormat[4];      // 4 banks: 0 = 17bit sign/mag, 1 = 16bit 2's, comp, 2 = 16b, 2's 1/2 scale
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 7)]
            public fixed UInt16 RESERVED1[7];
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256)]
            public fixed UInt16 GainArray[256];
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256)]
            public fixed UInt16 TrigThreshArray[256];
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 16)]
            public fixed UInt16 TrigEnableArray[16];    // 256 bits, 1/0 for each channel (max of 256 channels)
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 322)]
            public fixed UInt16 RESERVED2[322];         //  678-999
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 250)]
            public fixed UInt16 CustomArray[250];           // user custom space: 1000-1249
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 567)]
            public fixed UInt16 FactoryArray[567];          // start of factory table
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 32)]
            public fixed SByte ModelNumber[32];         // model number
            //[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 151)]
            public fixed UInt16 FactoryArray1[151];
            //public fixed UInt16 FactoryArray1[151];       // last piece of factory table
        };  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:56:49+00:00Added an answer on May 26, 2026 at 2:56 am

    A second answer, to answer your second question:

    The error messages are:

    Cannot assign to 'cfgPtr' because it is a 'fixed variable'.
    
    The right hand side of a fixed statement assignment may not be a cast expression.
    
    You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement. 
    

    The error messages are telling you what is wrong. Read them.

    Cannot assign to ‘cfgPtr’ because it is a ‘fixed variable’.

    You are assigning to it here:

    Arguments[i + 1] = *cfgPtr++;
    

    Once you initialize a variable containing a pointer that points to a fixed-in-space block you cannot change that variable because you might be changing it to point to a not-fixed-in-space block. In order to prevent this common bug, C# stops you from modifying that variable.

    If you want to modify the variable, create a different variable instead. Set it equal to cfgPtr and then modify that variable. Make sure you do it correctly; you are now responsible for ensuring that you keep the pointer pointing to something that is fixed.

    The right hand side of a fixed statement assignment may not be a cast expression.
    

    In my last answer I told you to read section 18.7 of the specification, which states that the “fixed” statement takes:

    A simple-name or member-access that references a fixed size buffer member of a moveable variable

    A cast expression is not a “simple name or member access”. A cast expression is a cast expression. And this cast doesn’t even make sense! A pointer to a structure is not a pointer to ushort!

    Remove the cast. Change the expression in the initializer to be a member access to a fixed-size buffer member of a moveable variable.

    You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement.
    

    You’re using a fixed-size buffer directly. You can’t do that. You can only use a fixed-size buffer by obtaining a pointer to it. Again, this is part of the safety system that ensures that you don’t accidentally access a fixed-in-size buffer that is not fixed-in-place. Stop trying to access the buffer directly. Obtain a pointer to the buffer and access it via the pointer.

    anybody who can explain to me will be great help since I am in short of time.

    Let me be very clear on this point: you have turned the managed safety system off and the correctness of your program and the stability of the process are now your problem, not the managed runtime’s problem. If you do not understand everything about how to safely manage your own pointers, stop what you are doing and read up on it until you do understand it. By rushing now and writing a whole lot of code that you do not understand, you are risking having to deal with horrible bugs later. This is no time to be in a hurry.

    Begin by reading all of chapter 18. Only once you thoroughly understand all that stuff should you attempt to write complicated unsafe code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been getting an error message that I can't resolve. It originates from
I have been all over this one, and I am just plumb stuck. I
I have two linqTOsql entities that has a parent and child relationship, one to
I'm reading the not so complete pytz documentation and I'm stuck on understand one
I'm stuck for ideas on this one. I'm working on a CMS that uses
I've been stuck with this problem for over a week now. Hopefully some one
I have an enum with a DescriptionAttribute on each member. Since I'm not able
I'm stuck on (what I think is) a simple views issue. I have a
I'm kinda stuck with this one so I hoped someone could help me. I
I am stuck in between of a problem where only one pass of regular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.