-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Move APIs for generated marshalling to different namespace - System.Runtime.Marshalling #68248
Comments
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsBackground and motivationFor .NET 7, we added various APIs used for p/invoke source generation:
These were all added to the API Proposal-namespace System.Runtime.InteropServices
+namespace System.Runtime.Marshalling
{
public sealed class LibraryImportAttribute : Attribute { ... }
public enum StringMarshalling { ... }
public sealed class NativeMarshallingAttribute : Attribute { ... ]
public sealed class MarshalUsingAttribute : Attribute { ... }
public sealed class CustomTypeMarshallerAttribute : Attribute { ... }
public enum CustomTypeMarshallerDirection { ... }
public enum CustomTypeMarshallerFeatures { ... ]
public enum CustomTypeMarshallerKind { ... }
public unsafe ref struct AnsiStringMarshaller { ... }
public unsafe ref struct ArrayMarshaller { ... }
public unsafe ref struct PointerArrayMarshaller { ... }
public unsafe ref struct Utf16StringMarshaller { ... }
public unsafe ref struct Utf8StringMarshaller { ... }
} API Usageusing System.Runtime.Marshalling;
[LibraryImport("NativeLib", StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
internal static partial string Method(string s1, string s2); Alternative Designs
RisksThis would be a breaking change between Preview 4 and 5. The new APIs were just exposed in Preview 4 and the source generator itself will not be included for public use until Preview 5. so we do not expect this to be very impactful.
|
@AaronRobinsonMSFT @jkoritzinsky I know when we talked before, I was into moving everything - including |
@elinor-fung Agreed on all accounts. I voiced a similar concern to @jkoritzinsky previously. I think we should have a conversation with the API review team and see what some of the API experts think of the concerns. |
namespace System.Runtime.InteropServices
{
public sealed class LibraryImportAttribute : Attribute { /*...*/ }
public enum StringMarshalling { /*...*/ }
}
// Was previously also approved for System.Runtime.InteropServices
namespace System.Runtime.InteropServices.Marshalling
{
public sealed class NativeMarshallingAttribute : Attribute { /*...*/ }
public sealed class MarshalUsingAttribute : Attribute { /*...*/ }
public sealed class CustomTypeMarshallerAttribute : Attribute { /*...*/ }
public enum CustomTypeMarshallerDirection { /*...*/ }
public enum CustomTypeMarshallerFeatures { /*...*/ }
public enum CustomTypeMarshallerKind { /*...*/ }
public unsafe ref struct AnsiStringMarshaller { /*...*/ }
public unsafe ref struct ArrayMarshaller { /*...*/ }
public unsafe ref struct PointerArrayMarshaller { /*...*/ }
public unsafe ref struct Utf16StringMarshaller { /*...*/ }
public unsafe ref struct Utf8StringMarshaller { /*...*/ }
} |
Background and motivation
For .NET 7, we added various APIs used for p/invoke source generation:
CustomTypeMarshallerAttribute
#66623These were all added to the
System.Runtime.InteropServices
namespace. We are proposing moving them to a separate namespace for clearer separation and discovery.API Proposal
API Usage
Alternative Designs
LibraryImportAttribute
(the triggering attribute for p/invoke source generation) inSystem.Runtime.InteropServices
and only move the new APIs (custom type marshalling attributes, marshaller implementations) that are directly related to marshallingSystem.Runtime.InteropServices
- for example,System.Runtime.InteropServices.Marshalling
Risks
This would be a breaking change between Preview 4 and 5. The new APIs were just exposed in Preview 4 and the source generator itself will not be included for public use until Preview 5. so we do not expect this to be very impactful.
The text was updated successfully, but these errors were encountered: