-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-System.Runtime.InteropServicesin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
Returning a ReadOnlySpan from a call generated by LibraryImport fails to compile, even though it should. It correctly works with a byte[] as the return type instead of ReadOnlySpan
Reproduction Steps
Compile the following code definition
[LibraryImport("wpiutil", EntryPoint = "WPI_GetResource_wpilib_128_png")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
[return: MarshalUsing(CountElementName = nameof(len))]
public static unsafe partial ReadOnlySpan<byte> GetResourceWpilib128Png(out nuint len);
Expected behavior
The code should compile
Actual behavior
The code fails with the following error
C:\Users\thadh\Documents\GitHub\robotdotnet\WPILib\src\wpiutil\Natives\ImagesNative.cs(13,53): error SYSLIB1051: The specified parameter needs to be marshalled from unmanaged to managed, but the marshaller type 'global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller<,>' does not support it. The generated source will not handle marshalling of the return value of method 'GetResourc
eWpilib128Png'. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1051) [C:\Users\thadh\Documents\GitHub\robotdotnet\WPILib\src\wpiutil\wpiutil.csproj]
C:\Users\thadh\Documents\GitHub\robotdotnet\WPILib\src\wpiutil\Microsoft.Interop.LibraryImportGenerator\Microsoft.Interop.LibraryImportGenerator\LibraryImports.g.cs(574,68): error CA1420: Managed parameter or return types require runtime marshalling to be enabled (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1420) [C:\Users\thadh\Documents\GitHub\robotdotnet\WPILib\
src\wpiutil\wpiutil.csproj]
Regression?
No response
Known Workarounds
No response
Configuration
.NET 8
Other information
No response
Metadata
Metadata
Assignees
Labels
area-System.Runtime.InteropServicesin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Type
Projects
Status
No status