Why does this code throw System.AccessViolationException when called from a C# project targeting Any CPU?
See the question and my original answer on StackOverflowWhat probably happens is you're (implicitely) using the same Type Library (.TLB), or DLL containing the .TLB, for the x64 and x86 versions.
The problem is your TLB defines an unmanaged structure, and this structure layout will be different in 32 bit and 64 bit mode (sizes, offsets, ...).
From .NET you want to make sure you're not referencing the same exact Interop Assembly (produced from the TLB by implicit tlbimp COM reference) when compiling with different processor architectures.
It can be tricky to get it right with standard Visual Studio tooling.
If you still want to use structs like this (which is kinda strange in the Automation world), I recommend you build Interop Assemblies using tlbimp.exe by yourself, and simply reference these Interop Assemblies like normal .NET assemblies, but depending on bitness (you will be able to tweak that using 'Condition' attributes in the .csproj) instead of using COM references directly.