Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I export a C# function with a JSValue argument? #414

Open
smx-smx opened this issue Jan 2, 2025 · 1 comment
Open

How do I export a C# function with a JSValue argument? #414

smx-smx opened this issue Jan 2, 2025 · 1 comment
Assignees

Comments

@smx-smx
Copy link

smx-smx commented Jan 2, 2025

As per issue title, I'm trying to export a C# class method using TypeExporter.ExportType, but the method is not exported due to the following check, which explicitly disallows JSValue argument types and causes the method to be skipped:

if (type.Assembly == typeof(JSValue).Assembly)
{
return false;

The method has the following signature:

public async Task<JSValue> sendMessage(JSValue parameters)

The purpose of the C# function is:

  • to call JSON.stringify
  • parse the result with System.Text.Json
  • execute some C# code,
  • serialize the result with System.Text.Json
  • call JSON.parse again to return the result to nodeJS.

(I know, the JSON round-trip could be removed in the future by creating a DTO type, but the JSON data currently has a dynamic structure and needs some work)

Changing the signature to a string and using JSON.stringify in NodeJs is a workaround to make the method appear, but I'd like to pass a JSON object directly.

@jasongin jasongin self-assigned this Jan 10, 2025
@jasongin
Copy link
Member

I thought that this should work. I'll investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants