简体   繁体   中英

AspNetCore InvalidOperationException

I am getting the following error:

System.InvalidOperationException: Unable to resolve service for type 
'Microsoft.AspNetCore.NodeServices.INodeServices' while attempting to activate 
'ConvertHighchart.Controllers.runNodeScriptController'.

My controller code is this:

using Microsoft.AspNetCore.NodeServices;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace ConvertHighchart.Controllers
{
[ApiController]
[Route("[controller]")]
public class runNodeScriptController : ControllerBase
{
    private readonly INodeServices _nodeServices;
    public runNodeScriptController(INodeServices nodeServices)
    {
        _nodeServices = nodeServices;
    }

    [HttpPost]
    public async Task<IActionResult> Post()
    {
        var result = "";
        try
        {
            result = await _nodeServices.InvokeExportAsync<string>("test_nodejs_script",
              "generateHighChart",
              "abc");
        }
        catch (System.Exception ex)
        {
        }

        return Ok(result);
    }
  }
}

Thanks

If you see this error while sending POST requests to the endpoint, have you put services.AddNodeServices(); in Startup?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM