The data region passed to the system call is too small. (Exception from hresult:0x8007007a)

Source: Internet
Author: User

Background:

In C # code, you need to convert a struct to a character array

The form of the structure is similar to the following:

struct usrinfo{    [MarshalAs (UnmanagedType.ByValArray, SizeConst = +)] public    char[] name;    public int ID;}

Call your own struct conversion function to convert it to a character array form

However, the following error is indicated: The data region passed to the system call is too small. (Exception from hresult:0x8007007a)

The first thing you need to do is to check that you assigned the name to a value that exceeds 16. And then look down!

Error message in: Marshal.structuretoptr (Structobj, Structptr, true); Method at

Troubleshooting

Find some materials on the Internet, and found that there are some similar situations. One situation is: there is no error in converting English, but it can be wrong to convert Chinese.

Test it, it really is. Because the program needs to use Chinese name, it does not appear in English when the error prompt.

Cause of Error:

When the structure is laid out, the Unicode code is not indicated, so there is an error when transferring the struct to the Structtoptr () method.

Workaround:

Use the StructLayout attribute to define the structure so that it is encoded in Unicode ( by setting the CharSet property)

The modified structure is defined as follows:

[StructLayout (LayoutKind.Sequential, CharSet=CharSet.Unicode)]struct usrinfo{    [MarshalAs ( UnmanagedType.ByValArray, SizeConst = +)] [public    char[] name;    public int ID;}

The data region passed to the system call is too small. (Exception from hresult:0x8007007a)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.