2
votes

I have a .dll that I generated thorugh a C++ project. I have to use this dll in my ASP.NET project and I have written DllImport functions for the same in my project.

The static class inside App_Code has some DllImport functions

public static class Functions
{
    [DllImport("MyFav.dll", EntryPoint = "fnmain", 
     CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern StringBuilder fnmain();
}

Since I could not add the C++ dll directly as a reference in my ASP.NET project (because it is not a .NET assembly), I just copied into the top level directory. ( Name of ASP.NET Project-> Right Click -> Add Existing Item )

Now, when I try to run the project, I get the following error:

Exception:

Unable to load DLL 'MyFav.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Any suggestions? Where has the .dll to be kept?

3
Maybe the dll is not found, maybe the dll found but you have use some libraries (like mfc) and not found on the directories that used by the asp.net accountAristos

3 Answers

1
votes

The .dll should be in the \bin folder of your asp.net application.

Apparently there are rules for how dlls are resolved. See Dynamic-Link Library Search Order on msdn

You could also try:

[DllImport("C:\path_to_dll\MyFav.dll", EntryPoint = "fnmain", 
 CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern StringBuilder fnmain();

If all this doesn't work, maybe your MyFav.dll has additional unresolved dependencies. You could use Dependency Walker to check for these.

1
votes

I had a similar error, but using Mono's XSP server. For this server, the solution is to put the dll in the root of your web app (the parent folder of ./bin). That happens to also be the current working directory (when run from Xamarin Studio), which is presumaby related.

0
votes

if to be used with out path copy paste the dll to bin directory in your project folder .