Cannot run in ASP.NET Web API

Issue #8 resolved
Eric Mayberry created an issue

I am unable to use AssimpNet in any ASP.NET Web API project. I have used this library in both a console application and class library project which work great, so I think it must be some kind of issue with how the assemblies are loaded for the web project.

In ASP.NET everything compiles fine, but when I hit an endpoint that imports any 3D file I get the following exception:

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

Any help would be greatly appreciated.

Comments (5)

  1. Nicholas Woodfield repo owner

    Make sure the native DLL is getting copied over to the same folder where the managed DLL is - or provide your own path to where it's located.

    Your console program works because there's a build script that gets installed via the nuget package that will copy the native DLLs to the target output folder. While I know next to nothing about ASP.NET, a cursory google search yielded a few hits and it sounds like others have similar issues, because the managed DLLs are shadow copied to a temp location (leaving the native DLLs behind since they aren't managed dependencies).

    https://stackoverflow.com/questions/344608/unmanaged-dlls-fail-to-load-on-asp-net-server

    That post may not be outdated, but either doing something special in deployment or creating a PATH environment variable for the assimp native DLLs should fix this.

  2. Eric Mayberry reporter

    Thanks, I did come across that SO article, but I have been manually copying the Assimp32 and Assimp64 dlls into the bin directory of my solution. I'm going to try copying them into Inetsrv and System32 as well...I'll let you know if that works.

  3. Eric Mayberry reporter

    Looks like that did the trick. I'll need to do some more research as to why it can find Assimp32.dll inside the Windows\SysWOW64 directory but not inside of the application's \bin folder. If I learn anything more I'll come back and post my findings.

    Thanks for getting back to me so soon!

  4. Log in to comment