Skip to content

(Unmanaged) Strings in callbacks are not considered as blittable by WasmAppBuilder #92380

@aienabled

Description

@aienabled

Description

The strings are not considered as blittable when defined in Pinvoke callbacks.

public static bool IsBlittable(Type type)
{
if (type.IsPrimitive || type.IsByRef || type.IsPointer || type.IsEnum)
return true;
else
return false;
}

if (!IsBlittable(p.ParameterType))
Error("Parameter types of pinvoke callback method '" + method + "' needs to be blittable.");

Reproduction Steps

private delegate void Callback_RegisterType(string typeName);
private static Callback_RegisterType _registerType = RegisterType;

[MonoPInvokeCallback(typeof(Callback_RegisterType))]
private static void RegisterType(string typeName)
{
}

Expected behavior

The above code should compile.

Actual behavior

WasmApp.Native.targets(290,5): Error : Parameter types of pinvoke callback method 'System.Void RegisterType(System.String)' needs to be blittable.

Regression?

No response

Known Workarounds

No response

Configuration

Tested on .NET 7.0.11. "WebAssembly Browser App" project type.

Other information

I'm working on porting a UI library to WASM and its C# SDK makes extensive use of strings in Pinvoke callbacks (dozens of methods). The C# SDK has no such error when building for other platforms (including WebGL in Unity).

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions