Non Asp.Net app: callback is not a function #124

Closed
opened 2025-08-09 17:15:05 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @samcov on 3/17/2018

Edit: This works fine in a Web Api situation, but something obviously is not fully initialized in the non Asp.Net situation.

I must be doing something wrong, but I can't see what it is. The callback is somehow undefined.

The node module looks like this:
module.exports = function (a, b, callback) {
let result = a + b;
callback(result);
};
The Main looks like this:
public static INodeServices _nodeServices;
static async Task Main(string[] args)
{
var services = new ServiceCollection();
services.AddNodeServices(noptions => {
noptions.ProjectPath = AppContext.BaseDirectory;
});

var serviceProvider = services.BuildServiceProvider();
_nodeServices = serviceProvider.GetRequiredService<INodeServices>();
var ret = await Add();

}
public static async Task Add(int x = 11, int y = 31)
{
try
{
return = await _nodeServices.InvokeAsync("./NodeScripts/Add.js", x, y);
}
catch(Exception ex)
{
var mess = ex.Message;
Console.WriteLine("Error: " + mess);
return -1;
}
}

*Originally created by @samcov on 3/17/2018* **Edit**: This works fine in a Web Api situation, but something obviously is not fully initialized in the non Asp.Net situation. I must be doing something wrong, but I can't see what it is. The callback is somehow undefined. **The node module looks like this**: module.exports = function (a, b, callback) { let result = a + b; callback(result); }; **The Main looks like this**: public static INodeServices _nodeServices; static async Task Main(string[] args) { var services = new ServiceCollection(); services.AddNodeServices(noptions => { noptions.ProjectPath = AppContext.BaseDirectory; }); var serviceProvider = services.BuildServiceProvider(); _nodeServices = serviceProvider.GetRequiredService<INodeServices>(); var ret = await Add(); } public static async Task<long> Add(int x = 11, int y = 31) { try { return = await _nodeServices.InvokeAsync<int>("./NodeScripts/Add.js", x, y); } catch(Exception ex) { var mess = ex.Message; Console.WriteLine("Error: " + mess); return -1; } }
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#124
No description provided.