无法在 ASP.NET 中使用 AssimpNet

Cannot use AssimpNet in ASP.NET

我可以创建一个新的控制台应用程序或 WinForms 应用程序并为 AssimpNet(版本 3.3.2)添加 NuGet 包,但是由于某些原因,当我尝试从一个新的 ASP.NET 中加载任何 3D 文件时Web API 项目我得到以下异常:

异常:

Error loading unmanaged library from path: Assimp32.dll, see inner exception for details.The specified module could not be found. (Exception from HRESULT: 0x8007007E)`

内部异常:

The specified module could not be found. (Exception from HRESULT: 0x8007007E)`

我尝试为 AnyCPU、x86 和 x64 编译我的项目,结果相同。只有在尝试使用该库时才会抛出此异常。其他端点仍然可以正常工作,并且所有内容都可以在没有任何警告的情况下编译。我可以使用全新的 ASP.NET Web API 项目始终重现此问题。

如有任何帮助,我们将不胜感激。

完整的错误消息和堆栈跟踪是:

An error has occurred.Error loading unmanaged library from path: Assimp32.dll, see inner exception for details.
The specified module could not be found. (Exception from HRESULT: 0x8007007E)Assimp.AssimpException   at Assimp.Unmanaged.AssimpLibraryWindowsImplementation.NativeLoadLibrary(String path)
   at Assimp.Unmanaged.AssimpLibraryImplementation.LoadAssimpLibrary(String path)
   at Assimp.Unmanaged.AssimpLibrary.LoadLibrary()
   at Assimp.Unmanaged.AssimpLibrary.CreatePropertyStore()
   at Assimp.AssimpContext.CreateConfigs()
   at Assimp.AssimpContext.ImportFile(String file, PostProcessSteps postProcessFlags)
   at Assimp.AssimpContext.ImportFile(String file)
   at AssimpTest.Controllers.ValuesController.Get(Int32 id) in c:\users\eric\documents\visual studio 2015\Projects\AssimpTest\AssimpTest\Controllers\ValuesController.cs:line 21
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()An error has occurred.The specified module could not be found. (Exception from HRESULT: 0x8007007E)System.IO.FileNotFoundException

事实证明,ASP.NET(或 IIS,我不确定是哪个)在服务器的 PATH 中某处寻找非托管 .dll。本地解决方案是将 Assimp32.dll 复制到 SysWOW64 中(是的,即使应用程序作为 64 位执行,也会使用 32 位库)。

在 Azure(托管我的生产环境)上,您可以通过 FTP 或 Kudu 为非托管库创建自定义文件夹,然后按照 this guide from Project Kudu 修改应用服务器的路径。

如果您在控制台或桌面应用程序中使用 运行 AssimpNet,它应该可以与复制到解决方案 \bin 文件夹的 Assimp32.dll 副本一起使用。如果有人能够解释 为什么 这对于控制台或桌面应用程序来说是不一样的,我会很乐意投赞成票。