You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Hi,
I'd like to invoke a node module that I on forehand don't know if it will return a stream or a json result. If I call InvokeAsync<object>() it works for json but for streams it throws the exception:
System.ArgumentException: Node module responded with binary stream. This cannot be converted to the requested generic type: System.Object.Instead you must use the generic type System.IO.Stream.
But obviously I can't use InvokeAsync<Stream>() if the result is json.
public static async Task MainAsync(string[] args)
{
var services = new ServiceCollection();
services.AddNodeServices(options => {
options.ProjectPath = Directory.GetCurrentDirectory();
});
var serviceProvider = services.BuildServiceProvider();
var nodeServices = serviceProvider.GetRequiredService<INodeServices>();
var result = await nodeServices.InvokeExportAsync<object>("test.js", "jsonfunc"); // works
result = await nodeServices.InvokeExportAsync<Stream>("test.js", "streamfunc"); // works
result = await nodeServices.InvokeExportAsync<object>("test.js", "streamfunc"); // throws
if (result is Stream)
{
// read from stream
}
else if (result is JObject)
{
// handle json response
}
}
test.js
module.exports.jsonfunc = function (callback) {
callback(null, { "hello": "world" });
};
module.exports.streamfunc = function (result) {
result.stream.write("hello world");
result.stream.end();
};
I'm using "Microsoft.AspNetCore.NodeServices": "1.1.0-beta-000002"
Hi,
I'd like to invoke a node module that I on forehand don't know if it will return a stream or a json result. If I call
InvokeAsync<object>()it works for json but for streams it throws the exception:System.ArgumentException: Node module responded with binary stream. This cannot be converted to the requested generic type: System.Object.Instead you must use the generic type System.IO.Stream.
But obviously I can't use
InvokeAsync<Stream>()if the result is json.test.js
I'm using "Microsoft.AspNetCore.NodeServices": "1.1.0-beta-000002"