Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net C# DllImport problem

I want to import DLL file in my web site project. I have dll file "my.dll" in folder C:\DLLDir and I'm using the code :

[DllImport("C:\\DLLDir\\my.dll", EntryPoint = "Out32")]

This works ok. But I want to use relative path (web site root path) . I'm trying to put "my.dll" in "bin" or root folder and I'm using the code :

   [DllImport("my.dll", EntryPoint = "Out32")]

but I'm getting the error: Unable to load DLL 'my.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Any ideas?

like image 553
user345602 Avatar asked Jan 09 '11 02:01

user345602


People also ask

What is ASP.NET C?

ASP.NET is an open-source, server-side web-application framework designed for web development to produce dynamic web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, applications and services. The name stands for Active Server Pages Network Enabled Technologies. ASP.NET (software)

What is ASP.NET C# used for?

ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites. It allows you to use a full featured programming language such as C# or VB.NET to build web applications easily.

Does .NET support C?

No. The . NET Framework is a bunch of classes(libraries) abstracting some lower-level windows functionality. C and C++ are languages.

Is .NET built on C?

. NET was fully written in C and C++ because the base was in assembly language. Integration of assembly with C is much easier compared to newer languages.


3 Answers

I think you may want to check out the following SO question first (since it's related to your case):

DllImport failed to locate DLL even though it is in the PATH

As other people has suggested, check the PATH environment variable to make sure that C:\DLLDir\ is there. You can read more about how to do configure your environment variables here.

Check out this MSDN forum post as well (seems like there was an issue with dependencies).

If it's a COM DLL you're importing then it might also requires to be registered first on a target machine (although I'm not sure if this is needed). Read more here.

like image 195
volpav Avatar answered Sep 22 '22 23:09

volpav


Either you did not copy my.dll to Bin folder where it should be loaded. Using Process Explorer ( http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) will likley show where it tries to load this file from.

EDIT: thanks to volpav for reminding that it is unmanaged DLL - ignore manged portion... ...assembly have some other dependencies. Check out http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx that details investiagtion of such failures (search for "assembly load fussion log" for more links).

like image 34
Alexei Levenkov Avatar answered Sep 21 '22 23:09

Alexei Levenkov


Go to Properties/Build tab, and set Platform target to x86.

like image 33
Mbt925 Avatar answered Sep 21 '22 23:09

Mbt925