-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Description
The custom marshaller analyzer has changed to require all element-focused marshal modes to satisfy both the managed-to-unmanaged and unmanaged-to-managed shapes.
Version
.NET 8 RC 1
Previous behavior
Custom marshallers with MarshalMode.ElementIn only need a ConvertToUnmanaged method. Custom marshallers with MarshalMode.ElementOut only need a ConvertToManaged method.
New behavior
SYSLIB1057 will be reported for custom marshallers with MarshalMode.ElementIn and MarshalMode.ElementOut that do not have both a ConvertToUnmanaged and ConvertToManaged method.
Type of breaking change
- Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
- Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
- Behavioral change: Existing binaries may behave differently at run time.
Reason for change
With the introduction of source-generated COM, the marshallers can be used in element scenarios in both managed-to-unmanaged and unmanaged-to-managed scenarios. This change updates the analyzer to ensure that user-defined marshallers have the required members for all scenarios where the marshaller may be used.
Recommended action
Add both a ConvertToManaged and ConvertToUnmanaged method to the marshaller type.
Feature area
Interop
Affected APIs
CustomMarshallerAttribute attributes with MarshalMode.ElementIn or MarshalMode.ElementOut.