The Code Anylsis engine produces this warning any time you have a managed type that includes a member of what it considers a "native" type. To be a native type, the field must:
- Be
IntPtr
,UIntPtr
, or aHandleRef
- Not be
static
- Actually be assigned a value from native code
I'm pretty sure that this third bullet is probably the difference between your various structures. The analysis engine (based on a quick dotPeek perusal) will only trigger the warning if it actually finds an instance of your IntPtr
being assigned from native code. I haven't yet found exactly what it considers an "assignment from native code" but whatever that is, my best guess is only one of you various struct
types is triggering that part of the rule.
Note that this is based on reading the actual code of the current implementation of the Code Analysis engine as ships with VS2010. It is absolutely not a documented behavior of the rule, but likely a specific optimization to reduce false positives. You should not assume that code which currently "passes" this rule (e.g. because it's never assigned from native code) will always do so, as MS is free to change the implementation details at any time.
As mentioned in my comment, suppressing the message is a perfectly legitimate response in this case; this is not one of the FxCop rules that should never be suppressed. The rule is very context-specific and only applies if you're allocating a native resource of your own. If you are only passing the struct back and forth between C# and unmanaged code, then you can most likely just suppress the warning and move on.