You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Different marshaller structs should be used for unmarshalling and marshalling elements in UnmanagedToManaged stubs #89463
Marshal structs (which managed the out value) should be freed in the catch block if the method will return failure. Unmarshal structs (which manage the in value) should free in the assign out stage.
changed the title [-]Different marshaller structs should be used for unmarshalling and marshalling elements in UnmanagedToManaged stubs. Marshal structs (which managed the out value) should be freed in the catch block if the method will return failure. Unmarshal structs (which manage the in value) should free in the assign out stage.[/-][+]Different marshaller structs should be used for unmarshalling and marshalling elements in UnmanagedToManaged stubs[/+]on Jul 25, 2023
Using different stateful marshaller instances in the UnmanagedToManagedRef case concerns me a little bit, as that's a significant change in design. In particular, sometimes it's important to have the same unmanaged value returned (like a pointer to an object) if the managed object hasn't changed. The inverse scenario (ManagedToUnmanagedRef) definitely has this case for SafeHandles. I think we should (if possible) require marshaller authors to handle this scenario for UnmanagedToManagedRef-mode marshallers instead of using separate instances for the in and out.
I could see a use case in saying "If there is no *Ref marshaller defined and no default, we will use the *In and *Out marshallers to provide the marshalling and handle the lifetime," but that would definitely be .NET 9 work.
Activity
[-]Different marshaller structs should be used for unmarshalling and marshalling elements in UnmanagedToManaged stubs. Marshal structs (which managed the out value) should be freed in the catch block if the method will return failure. Unmarshal structs (which manage the in value) should free in the assign out stage.[/-][+]Different marshaller structs should be used for unmarshalling and marshalling elements in UnmanagedToManaged stubs[/+]jkoritzinsky commentedon Jul 25, 2023
Using different stateful marshaller instances in the
UnmanagedToManagedRefcase concerns me a little bit, as that's a significant change in design. In particular, sometimes it's important to have the same unmanaged value returned (like a pointer to an object) if the managed object hasn't changed. The inverse scenario (ManagedToUnmanagedRef) definitely has this case forSafeHandles. I think we should (if possible) require marshaller authors to handle this scenario forUnmanagedToManagedRef-mode marshallers instead of using separate instances for theinandout.I could see a use case in saying "If there is no
*Refmarshaller defined and no default, we will use the*Inand*Outmarshallers to provide the marshalling and handle the lifetime," but that would definitely be .NET 9 work.dotnet-policy-service commentedon Apr 13, 2026
Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.