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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:02:04+00:00 2026-06-03T04:02:04+00:00

I have a struct which has a non-overlapping field reported as overlapped. [FieldOffset(8)] Int32

  • 0

I have a struct which has a non-overlapping field reported as overlapped.

[FieldOffset(8)]
Int32 X;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
[FieldOffset(12)]
string Y;

[FieldOffset(28)]
int Z;

The reported error is:

Could not load type ‘XXX’ … it contains an object field at offset 12 that is incorrectly aligned or overlapped by a non-object field.

It occurs only in Release configuration (TRACE, DEBUG flags and unsafe code are enabled, optimization is turned off), guessing – what happens to it?

UPD: thanks to @svick. Confirmed that x64 build is not what one wants for marshalling.

  • 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-06-03T04:02:06+00:00Added an answer on June 3, 2026 at 4:02 am

    First, Release configuration has nothing to do with this. What affects it is Platform Target: if you set it to x64, you will get this exception, but if you set it to x86, it will work fine.

    I think the reason for this behavior is that FieldOffset is used to specify the layout of the struct in the managed memory (even if the documentation doesn’t say this), but MarshalAs is not used in managed memory.

    Because of this, the object in managed memory contains a reference at offset 12. And since all references have to be aligned in .Net (to 4 bytes in 32-bit application and to 8 bytes in 64-bit), you get the exception if you run your application as 64-bit.

    So, the problem is not that you have overlapped fields, it’s the other part of the error message: the field is incorrectly aligned.

    The easy workaround is to compile the application as x86. If that’s not possible for you, I’m not sure how to fix this.

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

Sidebar

Related Questions

Lets say I have a Passenger struct, which has a field for a name.
I have a struct which has several arrays within it. The arrays have type
I have a class that has an inner struct/class (I have decided which yet,
Simple question. I have a struct which has a member that is also a
I have a struct which has a unique key. I want to insert instances
I am facing a small problem. I have a struct, which has a vector.
I have a struct which has some vectors as members: struct my_struct { std::vector<int>
-In my c code I have a struct which contains many unknown sized arrays
For example, I have a struct which is something like this: struct Test {
I have a struct called coordinate which is contained in a list in another

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.