Skip to content

JavaScript interop not marshalling Task<ArraySegment<byte>> and Task<Array> #77157

@FranklinWhale

Description

@FranklinWhale

Description

When exporting a .NET async method that returns Task<ArraySegment<byte>> or Task<Array>, error SYSLIB1072 is reported.

Exporting a .NET method that returns ArraySegment<byte> or Array works.

Reproduction Steps

  1. dotnet new wasmbrowser
  2. Add <LangVersion>preview</LangVersion> to <PropertyGroup> in the csproj file
  3. In Program.cs, add the following namespaces:
using System.Threading.Tasks;
using System.IO;
  1. Inside public partial class MyClass in Program.cs, add the following code:
[JSExport]
[return: JSMarshalAs<JSType.MemoryView>]
static ArraySegment<byte> GetMemoryView() {
	var stream = new MemoryStream();
	stream.TryGetBuffer(out var buffer);
	return buffer;
}

[JSExport]
[return: JSMarshalAs<JSType.Promise<JSType.MemoryView>>]
static Task<ArraySegment<byte>> GetMemoryViewAsync() => Task.Run(GetMemoryView);

[JSExport]
static byte[] GetBytes() => new byte[0];

[JSExport]
static Task<byte[]> GetBytesAsync() => Task.FromResult(GetBytes());
  1. dotnet run

Expected behavior

The build should be successful

Actual behavior

error SYSLIB1072: The type 'System.Threading.Tasks.Task<System.ArraySegment<byte>>' is not supported by source-generated JavaScript interop. The generated source will not handle marshalling of the return value of method 'GetMemoryViewAsync'.

error SYSLIB1072: The type 'System.Threading.Tasks.Task<byte[]>' is not supported by source-generated JavaScript interop. The generated source will not handle marshalling of the return value of method 'GetBytesAsync'.

Regression?

No response

Known Workarounds

No response

Configuration

.NET 7 RC2
Windows 10 Professional x64 21H2 Build 19044.2130

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions