How do I resolve "Please make sure that the file is accessible and that it is a valid assembly or COM component"?
Solution 1
the file is a native DLL which means you can't add it to a .NET project via Add Reference... you can use it via DllImport (see http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx)
Solution 2
In my case I had to register the .dll.
To do so, open cmd.exe
(the console) with admin rights and type:
regsvr32 "foo.dll"
Solution 3
Make sure the required dlls are exported (or copied manually) to the bin folder when building your application.
Solution 4
'It' requires a dll file called cvextern.dll . 'It' can be either your own cs file or some other third party dll which you are using in your project.
To call native dlls to your own cs file, copy the dll into your project's root\lib directory and add it as an existing item. (Add -Existing item) and use Dllimport with correct location.
For third party , copy the native library to the folder where the third party library resides and add it as an existing item.
After building make sure that the required dlls are appearing in Build folder. In some cases it may not appear or get replaced in Build folder. Delete the Build folder manually and build again.
Solution 5
I had the same program, I hope this could help.
I your using Windows 7, open Command Prompt-> run as Administrator. register your <...>.dll.
Why run as Administrator, you can register your <...>.dll using the run at the Windows Start, but still your dll only run as user even your account is administrator.
Now you can add your <...>.dll at the Project->Add Reference->Browse
Thanks
Omar Osama
graduated from computer science department, Helwan university, Egypt
Updated on July 05, 2022Comments
-
Omar Osama almost 2 years
I am building a project with OpenCV in C#. It requires a dll file called
cvextern.dll
. but, when adding this file as a reference, this message appears :-a reference "cvextern.dll" can't be added, Please make sure that the file is accessible and that it is a valid assembly or COM component.
I get tired from searching, I spent the past 2 days in searching for a solution for that problem
-
Omar Osama almost 13 yearsthe tutorial doesn't look like the reality .. Is the version of visual studio affects? I am using microsoft visual studio 2008 express edition .. :)
-
Yahia almost 13 yearsAFAIK is doesn't really matter... though the DLL must be either in the project directory or "globally accessible" (like system32...)
-
SSpoke almost 9 yearsThis is the answer probably 95% can of this error can be solved by doing this cmd ->
regsvr32 "C:\blah\foo.dll"
-
Binarian about 8 yearsYes, since I could not add it as a reference but another DLL needed this. Simply copying at compile time worked.
-
corporateAbaper about 7 yearsBut how do you debug calls to that external dll if you can't add a reference to it in the project?
-
Soylent Graham almost 7 years@DavidNogueira to debug the external DLL, you can attach your DLL-project (ie, the source & solution that built the DLL) to the process that loads the DLL at runtime. If the DLL being loaded and source match up, visual studio will let you step through the code
-
Mansinh over 6 yearsThis helps for me Thank you
-
StayOnTarget about 6 yearsIf possible you ought to copy the relevant details into your answer.
-
gneri about 6 yearsI don't know if possible, but I understand we should have it here in case the link stops functioning.
-
Sushil Jadhav over 5 yearsMy program shows "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)" error but by changing project build option from Any CPU to X86 solved my issue. refer for more details.
-
SeanMC over 5 yearsI still get a similar error when I run this command. make sure the file is stored at the specified path etc
-
SeanMC over 5 yearsSome more details about "Add as existing item", once I copied the DLL to my bin/debug directory, in VS code I went to Project > add existing item> myLibrary.dll -it worked. Thanks for the tip! -See this: docs.microsoft.com/en-us/sql/ssms/solution/…
-
Yusha over 5 yearsUnfortunately what Yahia is saying is only partially true. IFF you don't have the file in your project directory, then you can't add it via Add Reference... Otherwise you should be fine. Just add it to the project directory. Don't do this ugly DllImport inside of code, that's hideous.
-
makri aymen abderraouf almost 3 yearsthis not working for me , when i wanna add the dll to the references is shows the error of the question and when i add it as you said the app exit with this code => has exited with code 255 (0xff). <=