title | description | ms.date | f1_keywords | helpviewer_keywords | dev_langs | |||||
---|---|---|---|---|---|---|---|---|---|---|
CA1421: Method uses runtime marshalling when 'DisableRuntimeMarshallingAttribute' is applied |
Learn about code analysis rule CA1421: Method uses runtime marshalling when 'DisableRuntimeMarshallingAttribute' is applied |
11/16/2022 |
|
|
|
Property | Value |
---|---|
Rule ID | CA1421 |
Title | Method uses runtime marshalling when DisableRuntimeMarshallingAttribute is applied |
Category | Interoperability |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 8 | As suggestion |
A method uses runtime marshalling, and runtime marshalling is explicitly disabled.
If a method uses runtime marshalling when runtime marshalling is disabled, it can cause unexpected behavior differences at run time due to different expectations of a type's native layout.
Enable runtime marshalling or use features like sizeof
and pointers to ensure accurate results.
Don't suppress a warning from this rule.
The following code snippet shows a violation of CA1421:
:::code language="csharp" source="snippets/csharp/extra-rules/ca1421.cs"::: :::code language="vb" source="snippets/vb/extra-rules/ca1421.vb":::
To fix the violation, remove the xref:System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute attribute on the assembly.