Page 1 of 1

TypeLoadException with dependency free fork

Posted: Tue Jul 02, 2013 6:11 am
by manabreak
Hiya,

I downloaded the dependency free fork yesterday. It builds nicely, but when I try to initialize a new Space(), it throws a TypeLoadException. It says that loading EntityStateChange from the assembly failed. I noticed an old post depicting the same problem and the solution back then was to change the assembly name to something else, but it didn't help. I also tried both 32-bit and 64-bit builds to no avail. Any ideas?

Edit: Whoops, noticed that the exception differs between 32-bit and 64-bit builds. In the case of 32-bit, it's BadImageFormatException.

Edit 2: I managed to fix the 32-bit problem. I had to change my own project's platform target to x86, instead of using "Any CPU".

Re: TypeLoadException with dependency free fork

Posted: Tue Jul 02, 2013 6:24 pm
by Norbo
The EntityStateChange is a struct with explicit layout and contains a reference field. The required alignment for reference fields in structs differs between 32 bit (4 byte aligned) and 64 bit builds (8 byte aligned). To fix it, set the offset of the 'target' to be 8 byte aligned, like so:

Code: Select all

        [StructLayout(LayoutKind.Explicit)]
        internal struct EntityStateChange
        {
            [FieldOffset(0)]
            internal Quaternion orientationQuaternion;
            [FieldOffset(0)]
            internal Vector3 vector;
            [FieldOffset(16)]
            internal TargetField targetField;
            [FieldOffset(24)] //24 instead of 20!
            internal Entity target;
        }
This will be fixed in the dependency free fork when v1.3.0 is released and the changes from the main branch are propagated.

Re: TypeLoadException with dependency free fork

Posted: Wed Jul 03, 2013 9:19 am
by manabreak
Okay, cool. :) By the way, I swapped majority of the dependency free fork's math classes with OpenTK's math classes, and they worked without any hassle. No need to use two different Vector3's and Quaternions. :)