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 7042705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:12:02+00:00 2026-05-28T02:12:02+00:00

I am building a COM wrapper written in C# around a C dll and

  • 0

I am building a COM wrapper written in C# around a C dll and am getting an error when I call one particular function which takes a reference to a pre-initialized array of structs.

The error is: “An unhandled exception of type ‘System.ExecutionEngineException occurred in sXEposCOM.dll”

The C function has a signature as follows:

UINT16 sXGetSupportedSchemes( SXEposScheme_t *pSchemes );

And the SXEposScheme_t struct in the C dll is declared as:

typedef struct _SXEposScheme_t
{
BYTE    schemeID[SX_EPOS_SID_LENGTH];
char    schemeName[SX_EPOS_MAX_SCHEME_NAME_LENGTH];
} SXEposScheme_t;

In my C# wrapper (sXEposCOM) I have the following:

private const int SX_EPOS_SID_LENGTH    = 2;
private const int SX_EPOS_MAX_NUM_SCHEMES = 10;

[DllImport("SXEposDll.dll")]
private static extern UInt16 sXGetSupportedSchemes(ref SXEposScheme_t [] pSchemes);

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SXEposScheme_t
{
    [MarshalAs(
    UnmanagedType.ByValArray,
    SizeConst = SX_EPOS_SID_LENGTH)]
    public byte[] schemeID;
    [MarshalAs(
    UnmanagedType.ByValArray,
    SizeConst = SX_EPOS_MAX_SCHEME_NAME_LENGTH)]
public char [] schemeName;
}

public int GetSupportedSchemes()
{
    uint result = 0;
    uint schemeCnt = 0;
    GetNumSchemes(ref schemeCnt); //This call to the C dll succeeds and returns 2 to   schemeCnt

    SquidEposScheme_t[] schemes = new SXEposScheme_t[schemeCnt];    
    result = sXGetSupportedSchemes(ref schemes); //Errors on this line with An unhandled exception of type 'System.ExecutionEngineException occurred in sXEposCOM.dll

...
...
return result;
}       

Can anyone tell me why I am getting this error?

  • 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-28T02:12:03+00:00Added an answer on May 28, 2026 at 2:12 am

    This exception is triggered when the native code corrupts the garbage collected heap. Plenty of opportunity here, your C# declarations look wrong. An array is already passed as a pointer, adding ref to the argument makes it a pointer to a pointer. Possible fix:

    [DllImport("SXEposDll.dll")]
    private static extern UInt16 sXGetSupportedSchemes([In,Out] SXEposScheme_t [] pSchemes);
    

    Pack=1 is very rarely appropriate, use ByValTStr to marshal a string. Possible fix:

    [StructLayout(LayoutKind.Sequential)]
    public struct SXEposScheme_t
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = SX_EPOS_SID_LENGTH)]
        public byte[] schemeID;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SX_EPOS_MAX_SCHEME_NAME_LENGTH)]
        public string schemeName;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam getting the following linker error while building an atl com dll which is
I'm building a C# application that loads a 32-bit COM dll. The compiled application
I am building a site in asp.net and have multiple subdomains. For example, one.cookies.com
I am building an application in C# which uses com.gargoylesoftware.htmlunit.WebClient to access and retrieve
I'm building a library (https://github.com/OscarGodson/storageLocker), a localStorage wrapper to be more exact, but because
I'm trying to figure out how imgur.com is building their gallery (the one on
I am building a website www.etutornetwork.com, in top menu I have included a link
I'm building a Rails app that has Etsy.com style functionality. In other words, it's
I'm building up my site over at http://royronalds.com , and I'm trying to figure
I am building CLR Stored Procedures and UDFs as discussed in this article: http://www.codeproject.com/KB/cs/CLR_Stored_Procedure.aspx

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.