首页 > 解决方案 > FFTW.NET DFT.FFT(pinIn, pinOut) 在 WEB API 中抛出 System.InvalidOperationException

问题描述

我想在 .NET Core 2.1 WEB API 中使用 FFTW.NET。当我执行下面的一段代码时,我得到System.InvalidOperationException: 'IsAvailable returns false.'DFT.FFT(pinIn, pinOut);

        Complex[] input = new Complex[1024];
        Complex[] output = new Complex[input.Length];

        //Initialize input         

        using (var pinIn = new PinnedArray<Complex>(input))
        using (var pinOut = new PinnedArray<Complex>(output))
        {
            DFT.FFT(pinIn, pinOut);
        }

下面是堆栈跟踪。

   at FFTW.NET.FftwPlan`2..ctor(IPinnedArray`1 buffer1, IPinnedArray`1 buffer2, Int32 rank, Int32[] n, Boolean verifyRankAndSize, DftDirection direction, PlannerFlags plannerFlags, Int32 nThreads)
   at FFTW.NET.FftwPlanC2C.Create(IPinnedArray`1 input, IPinnedArray`1 output, DftDirection direction, PlannerFlags plannerFlags, Int32 nThreads)
   at FFTW.NET.DFT.Transform(IPinnedArray`1 input, IPinnedArray`1 output, DftDirection direction, PlannerFlags plannerFlags, Int32 nThreads)
   at FFTW.NET.DFT.FFT(IPinnedArray`1 input, IPinnedArray`1 output, PlannerFlags plannerFlags, Int32 nThreads)
   at FFTW_WEB_API.Controllers.ValuesController.Get() in D:\FFTW_Test\FFTW_WEB_API\Controllers\ValuesController.cs:line 1059
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()

但是同一段代码在 .NET Core 2.1 控制台应用程序中运行良好。

如果我做错了什么,请提出建议。

标签: c#asp.net-core-webapiasp.net-core-2.1fftw.net-core-2.1

解决方案


IsAvailable在内部调用以测试互操作层是否快乐 -在这里找到

false如果尝试加载 Dll 导致DllNotFoundException(通过GetVersionAndInitializeand _version),它看起来会返回。

因此,本机 DLL 不在加载的正确位置。如果不清楚正在为 DLL 探测哪些位置,您可能希望使用进程监视器来查找加载 DLL 的失败探测尝试。


推荐阅读