My ASP.NET MVC App uses an unmanaged external DLL written in C++.
This website runs fine from within Visual Studio, locating and accessing the external DLLs correctly. However, when the website is published on a local webserver (running IIS 7.5) rather than the Visual studio IIS Express I get the following error:
HTTP Error 503. The service is unavailable.
The external DLL is located in the bin directory of the website.On having a look at the IIS logs I noticed the defaultapppool stops everytime I call the dll.
HTTP/1.1 GET /Bio/Select/3 503 1 Disabled DefaultAppPool
I have tried the following:
Below is a code snippet of how I call the dll
[HttpGet]
public ActionResult Select(int ID)
{
int res = BSSDK.BS_InitSDK();
if (res != BSSDK.BS_SUCCESS)
{
ModelState.AddModelError("Error", "SDK failed to initialise");
}
return View()
}
public class BSSDK
{
[DllImport("BS_SDK.dll",
CharSet = CharSet.Ansi,
EntryPoint = "BS_InitSDK")]
public static extern int BS_InitSDK();
}
My view
@model IEnumerable<BasicSuprema.Models.BioUser>
@using GridMvc.Html
@{
ViewBag.Title = "Bio Users On DB";
}
<div class="well well-sm"><h3>@ViewBag.Title</h3></div>
@Html.ValidationMessage("Error")
<div class="grid-wrap">
@Html.Grid(Model).Named("UsersGrid").Columns(columns =>
{
columns.Add(c => c.BioUserID).Titled("ID");
columns.Add(c => c.UserName).Titled("User");
}).WithPaging(10).Sortable(true)
</div>
Similar questions include Unmanaged DLLs fail to load on ASP.NET server How to call unmanaged code in ASP.NET website and host it in IIS
Unable to call the DLL from ASP.NET
When I hosted it on web server running IIS 8 I get the below error.So maybe on my local IIS server it returns error 503 coz it can't find the dll but am yet to determine this as for the hosted one I dont have access to copy the dll to the system folders.
Unable to load DLL 'BS_SDK.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
In order to find out where your application searches for your dll, I recommend Microsoft FusionLog. It will not only log where the CLR searches for dlls, it will also log more details on why loading failed.
Additionally, it might be helpful to see if the process actually opens a file handle for the dll. You can find out via Process Explorer: * Download ProcessExplorer and run it as administrator. * Add a filter for 'Process Name' and use 'w3wp.exe' * Start up your application pool * Search process explorer for 'BS_SDK.dll' and you will see from which directory it tried to load it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With