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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:44:42+00:00 2026-05-11T02:44:42+00:00

Youll need a 64bit machine if you want to see the actuall exception. I’ve

  • 0

Youll need a 64bit machine if you want to see the actuall exception. I’ve created some dummy classes that repro’s the problem.

[StructLayout(LayoutKind.Sequential, Pack = 1)]     public class InnerType     {         char make;         char model;         UInt16 series;     }   [StructLayout(LayoutKind.Explicit)]     public class OutterType     {         [FieldOffset(0)]         char blah;          [FieldOffset(1)]         char blah2;          [FieldOffset(2)]         UInt16 blah3;          [FieldOffset(4)]         InnerType details;     }      class Program     {         static void Main(string[] args)         {             var t = new OutterType();             Console.ReadLine();         }     } 

If I run this on the 64 clr, I receive a type load exception,

System.TypeLoadException was unhandled    Message='Could not load type 'Sample.OutterType' from assembly 'Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field.' 

If i force the target cpu to 32, it works fine.

Also, if i change InnerType from a class to a struct it also works. Can someone explain whats going on or what I am doing wrong ?

thanks

  • 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. 2026-05-11T02:44:43+00:00Added an answer on May 11, 2026 at 2:44 am

    The part about overlapping types is misleading here. The problem is that in .Net reference types must always be aligned on pointer size boundaries. Your union works in x86 since the field offset is 4 bytes which is the pointer size for a 32 bit system but fails on x64 since there it must be offset a multiple of 8. The same thing would happen if you set the offset to 3 or 5 on the x86 platform.

    EDIT: For the doubters – I couldn’t find a ready reference on the internet but check out Expert .NET 2.0 IL Assembler By Serge Lidin page 175.

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

Sidebar

Related Questions

Sometimes when writing a class you'll need some helper methods that take care of
class MyClass { private function isExist($arr) { // need to do some formatting here
I want to create a contact listener in such a way that I'll be
I believe that IDictionary classes works better with sortable objects. I believe also that
Iam having some problems with a function I wrote. I want to wrap this
I need that hibernate read a sql file and do whatever it needs to
A co-worker posed this question to me, and I told them, No, you'll need
I need to position this update button on www.euroworker.no/order (you'll have to add an
Cappuccino is one. With Cappuccino, you don't need to know HTML. You'll never write
If you view source on http://seeitornot.co/prometheus/771228969 , you'll see html in the including the

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.