Skip to content

Function signature mismatch when calling native WASM function that takes i64/long #112262

Closed

Description

@r58Playz

Description

An Uncaught RuntimeError: null function or function signature mismatch is thrown when attempting to call a [DllImport]ed function that takes an enum with ulong variant on WASM.

Reproduction Steps

Default wasmbrowser template with these changes:

Program.cs

using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.JavaScript;

Console.WriteLine("Hello, Browser!");

[Flags]
public enum Flags  : ulong { X = 1 }

public partial class MyClass
{
    [JSExport]
    internal static string Greeting()
    {
        i64func(Flags.X);
        var text = $"Hello, World!";
        Console.WriteLine(text);
        return text;
    }

    [DllImport("Program")]
    extern static void i64func(Flags var);
}

Program.c

#include <stdio.h>
#include <stdint.h>

void i64func(uint64_t var) {
	printf("test %lld \n", var);
}

i64-fail.csproj

<Project Sdk="Microsoft.NET.Sdk.WebAssembly">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <WasmBuildNative>true</WasmBuildNative>
  </PropertyGroup>

  <ItemGroup>
    <NativeFileReference Include="Program.c" />
  </ItemGroup>
</Project>

Expected behavior

i64func should print the number that it was passed to the console when called.

Actual behavior

i64func throws Uncaught RuntimeError: null function or function signature mismatch when called.

Image

Regression?

No response

Known Workarounds

No response

Configuration

  • OS: Arch Linux
  • dotnet: 9.0.102
  • Host architecture: x86_64
  • Browser: Chrome, Firefox

Other information

No response

Edit: Made my repro closer to what my full code is erroring on and fixed image

Activity

  1. ghost added
    needs-area-label
    on Feb 7, 2025
  2. added
    untriaged
    on Feb 7, 2025
  3. added
    arch-wasm
    and removed
    needs-area-label
    on Feb 7, 2025
  4. added this to the 10.0.0 milestone on Feb 7, 2025
  5. removed
    untriaged
    on Feb 7, 2025
  6. lewing commented on Feb 9, 2025

    @lewing
    Member

    @kg any idea what might be going wrong here?

  7. kg commented on Feb 9, 2025

    @kg
    Contributor

    Does it work if you cast the enum to uint64 and make the signature of the pinvoke uint64?

  8. added
    needs-author-action
    on Feb 9, 2025
  9. r58Playz commented on Feb 9, 2025

    @r58Playz
    Author

    Yes, it works fine if I do that.

  10. added
    needs-further-triage
    and removed
    needs-author-action
    on Feb 9, 2025
  11. kg commented on Feb 9, 2025

    @kg
    Contributor

    I think we historically have some limitations around enums and basetypes, so this is probably one of those cases. I know JS interop previously treated all enums as int32 so it doesn't surprise me that the same is true for pinvoke.

    For now, please use the workaround, but we'll definitely keep this issue open and try to fix it.

  12. modified the milestones: 10.0.0, 11.0.0 on Aug 5, 2025
  13. added a commit that references this issue on Jul 19, 2026
    1ac1027
  14. locked and limited conversation to collaborators on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-System.Runtime.InteropServices.JavaScriptneeds-further-triage

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions