-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
The strings are not considered as blittable when defined in Pinvoke callbacks.
runtime/src/tasks/WasmAppBuilder/PInvokeCollector.cs
Lines 170 to 176 in a5b75b8
| public static bool IsBlittable(Type type) | |
| { | |
| if (type.IsPrimitive || type.IsByRef || type.IsPointer || type.IsEnum) | |
| return true; | |
| else | |
| return false; | |
| } |
runtime/src/tasks/WasmAppBuilder/PInvokeCollector.cs
Lines 141 to 142 in a5b75b8
| 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
Labels
Type
Projects
Status