Skip to content

[Breaking change]: Custom marshallers with MarshalMode.ElementIn and MarshalMode.ElementOut now must have both managed-to-unmanaged and unmanaged-to-managed shapes. #36554

@jkoritzinsky

Description

@jkoritzinsky

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.


Associated WorkItem - 156740

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.breaking-changeIndicates a .NET Core breaking changesource incompatibleSource code may encounter a breaking change in behavior when targeting the new version.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions