How to add FreeImage.dll to C# project - c#

I have successfully added other .dll files to other C# project this way:
Right click Reference > Add Reference > Browse > Double click the .dll file
but Microsoft Visual Studio 2008 issues the following complaint:
A reference to ...\dll\FreeImage.dll could not be added.
Please make sure that the file is accessible,
and that it is a valid assembly or COM component.
I am using .NET Framework 3.5. I believe this is a 32bit dll (it downloaded with FreeImage3151Win32) so I changed the configuration of the project to x86.
What is the correct method to add FreeImage.dll to a C# project?

Use the wrapper provided in the download. There are C# samples in the \Wrapper\FreeImage.NET\cs\Samples directory.

The FreeImage.dll isn't a .Net dll. You need to write a wrapper in .Net which call the methods of the unmaged code. There is an example here but they also supply a .net wrapper in the binary distribution here

I've seen this before with files downloaded from the Internet that are "blocked" by the file system. Try going into the file's properties and clicking the "Unblock" button.

In the current release (3.15.4), have to build the project in FreeImage\Wrapper\FreeImage.NET\cs to produce the DLL for C#. Then you find it in FreeImage\Wrapper\FreeImage.NET\cs\Library\bin\Release or Debug.

Save the file into the Bin folder and click Project > Add Reference > Browse > Double click the .dll file
C# sharp helps link

Related

Visual Studio 2013 C# configuration settings

I want to add include directories and libraries in my c# project like i can in my c++ project
C++ Project : There are options to include directories and linker dependencies.
C# Project
There does not appear to be an option in the project settings to add those settings. I added the path in reference path, but my debugger throws an error. Right now i've added all the dll in my project\bin\debug directory and its working, but i don't want to do it for all the projects. Where i can link these diretories ?
you can add reference of library files which you want to add into your project by right clicking the project under solution explorer and then "add reference" and then browse or select from the list of dlls..
You can't. You have to include references to code files and assemblies one by one.
The linker and compiler for .NET works different than you are used to with c++. That's why you can't just link an entire directory containing some code files / assemblies.
Add reference to your existing dll for every project which will be use it
http://msdn.microsoft.com/en-us/library/7314433t(v=vs.90).aspx
https://www.google.it/search?q=add+reference+c%23&es_sm=122&source=lnms&tbm=isch&sa=X&ei=P-2fU472Bcr00gX-tYAw&ved=0CAoQ_AUoAw&biw=1920&bih=955

How do I resolve "Please make sure that the file is accessible and that it is a valid assembly or COM component"?

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
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)
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"
Make sure the required dlls are exported (or copied manually) to the bin folder when building your application.
'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.
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
Look here for the answer by TheMattster. I implemented it and it worked like a charm. In a nutshell, his solution suggests to add the COM dll as a resource to the project (so now it compiles into the project's dll), and upon the first run write it to a file (i.e. the dll file I wanted there in the first place).
The following is taken from his answer.
Step 1) Add the DLL as a resource (below as "Resources.DllFile"). To do this open project properties, select the resources tab, select "add existing file" and add the DLL as a resource.
Step 2) Add the name of the DLL as a string resource (below as "Resources.DllName").
Step 3) Add this code to your main form-load:
if (!File.Exists(Properties.Resources.DllName))
{
var outStream = new StreamWriter(Properties.Resources.DllName, false);
var binStream = new BinaryWriter(outStream.BaseStream);
binStream.Write(Properties.Resources.DllFile);
binStream.Close();
}
My problem was that not only I had to use the COM dll in my project, I also had to deploy it with my app using ClickOnce, and without being able to add reference to it in my project the above solution is practically the only one that worked.
In my case I also have unmanaged dll's (C++) in workspace and if you specify:
<files>
<file src="bin\*.dll" target="lib" />
</files>
nuget would try to load every dll as an assembly, even the C++ libraries! To avoid this
behaviour explicitly define your C# assemblies with references tag:
<references>
<reference file="Managed1.dll" />
<reference file="Managed2.dll" />
</references>
Remark: parent of references is metadata -> according to documentation
https://learn.microsoft.com/en-us/nuget/reference/nuspec#general-form-and-schema
Documentation: https://learn.microsoft.com/en-us/nuget/reference/nuspec

How to include the reference of DocumentFormat.OpenXml.dll on Mono2.10?

I am using C#.net Windows Desktop Application.I want to run these application with other platform also. So, i am using Mono 2.10 as a cross compiler.While running,unexpectedly my Application is terminated by saying the error message like
Error:Could not open the selected folder.
Could not load a file or assembly 'DocumentFormat.OpenXml.dll,version=2.0.5022.0, culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
I don't know what is problem here...I have installed openxml sdk2.0 on c:\program files\open xml sdk\v2\lib\DocumentFormat.OpenXml.dll.
and also put my application eXe on on the same place for testing purpose...
Please guide me to solve this issue...
Being new to this myself, here's what I did:
I'm using MS Visual Studio 2010 Pro.
Download and install the OpenXML SDK
Within my project in Visual Studio, select "Project" then "Add Reference"
Select the "Browse" tab
In the "Look in:" pull down, navigate to:
C:\Program Files(x86)\Open XML SDK\V2.0\lib and select the "DocumentFormat.OpenXml.dll
Hit OK
In the "Solution Explorer" (on the right for me), the "References" folder now shows the DocumentFormat.OpenXML library.
Right-click on it and select Properties
In the Properties panel, change "Copy Local" to "True".
You should be off and running now using the DocumentFormat classes.
You should also ensure you set a reference to WindowsBase. This is required to use the SDK as it handles System.IO.Packaging (which is used for unzipping and opening the compressed .docx/.xlsx/.pptx as an OPC document).
select DocumentFormat.OpenXml under references , view it's properties, and set the Copy Local option to True so that it copies it to the output folder. That worked for me.
Goto Nuget Package manager and search for openxml. And install DocumentFormat.OpenXml
What worked for me:
Add a folder to the project call it ThirdParty.
Add in the ThirdParty folder both DocumentFormat.OpenXML.dll and WindowsBase.dll
Make sure the the project uses the ThirdParty dir as reference for both the DLLs
Build and published to an external server.
Well, In my applications I just need to Add a reference to "DocumentFormat.OpenXml" under .Net tab and both references (DocumentFormat.OpenXml and WindowsBase) are always added automatically. But They are not included within the Bin folder. So when the Application is published to an external server I always place DocumentFormat.OpenXml.dll under the Bin folder manually. Or set the reference "Copy Local" property to true.
You need to have DocumentFormat.OpenXML.dll in the same folder as your application - or in the 'bin' path if you are developing an ASP.NET application. However, I'm not certain that the OpenXML SDK is supported on non-Windows operating systems - you may need to look into a third-party solution.
Yes, this answer is right, the only difference is that you copy your .dll into bin folder of the project.
After viewing and changed the properties to DocumentFormat.OpenXml, I also had to change the Specific Version to false.
I found that when mixed with PCL libraries the above problem presented itself, and whilst it is true that the WindowsBase library contains System.IO.Packaging I was using the OpenXMLSDK-MOT 2.6.0.0 library which itself provides it's own copy of the physical System.IO.Packaging library. The reference that was missing for me could be found as follows in the csharp project
<Reference Include="System.IO.Packaging, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\OpenXMLSDK-MOT.2.6.0.0\lib\System.IO.Packaging.dll</HintPath>
<Private>True</Private>
</Reference>
I downgraded my version of the XMLSDK to 2.6 which then seemed to fix this problem up for me. But you can see there is a physical assembly System.IO.Packaging.dll
The issue for me was that DocumentFormat.OpenXml.dll existed in the Global Assembly Cache (GAC) on my Win7 development box. So when publishing my project in VS2013, it found the file in the GAC and therefore omitted it from being copied to the publish folder.
Solution: remove the DLL from the GAC.
Open the GAC root in Windows Explorer (Win7: %windir%\Microsoft.NET\assembly)
Search for OpenXml
Delete any appropriate folders (or to be safe, cut them out to your desktop in case you should want to restore them)
There may be a more proper way to remove a GAC file (below), but that is what I did and it worked.
gacutil –u DocumentFormat.OpenXml.dll
Hope that helps!

C# lib install?

I downloaded two different packages, they both came with an .XML and a .DLL file. I used some of their source code and couldn't get it to work (missing namespace). How do I install the XML file and the DLL file? I know the dll should go into system32/system but what do I do with the xml file?
You don't need to install the DLL at all, actually. Just add it as a Reference to your project, then use it as normal.
The XML file isn't specifically necessary. It can be used to generate documentation for the DLL, if you so desire.
EDIT: Also make sure that "Copy Local" (or something similar, can't recall the exact wording) is set to True in the properties of the reference. This will ensure that the DLL is in the same directory as your exe. Otherwise it probably won't be in the load path and then your app won't run.
You don't need to put it on any particular place (that system32 comment is an older technology).
Based on the issue you mentioned (missing namespace -> when compiling), you just need to add the reference to your project (right click on project->add reference->browse->select the .net dll).

Convert .cs to .dll

How can I compile a .cs file into a DLL?
My project name is WA. In my bin folder after the compilation, I found:
WA.exe
WA.vshost.exe
WA.pdb
You have to compile it:
csc /t:library source.cs -> source.dll
Are you using Visual Studio?
If you create a Class Library project in VS, add your .cs file and then compile the project, the output will be a .dll file.
You use a compiler. Csc.exe comes with the .NET Framework.
Check this link: http://msdn.microsoft.com/en-us/library/78f4aasd.aspx
You can also use an IDE like Visual Studio if you want the development process to be easier.
Its automatically created for you when you run a build in visual studio. Check the bin folder in your project folder.
For your information there are two kinds of DLL file which named "Managed" and "Un-Managed". Managed type is which you can use and add to your references in Visual Studio IDE.
However, if you want to convert each classes separately to Dll, you can use new windows application-> class library. After debugging and running that you can find DLL file in your source destination. Try it.
P.S: Usually you forced to use more than one class in one DLL file.

Categories

Resources