adding a dll to c# project and using the dll functions

k11

enter image description hereI am trying to import a dll in my c# console project. I add the dll in the reference of the project. Right Click->add reference->browse. The DLL is placed in my project folder as well as in program data folder in c drive.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using mcp2210;

the last line "using mcp2210;" gives an error

Error 1 The type or namespace name 'mcp2210' could not be found (are you missing a using directive or an assembly reference?) C:\Users\testuser\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs

Do I need to use [DllImport("mcp2210.dll")] in my project? How can I access the functions of this dll?

Please see the images below

edit

Hi I was able to add the dll in my project using the namespace from the object browser. However when I try to run it in debug mode I get badImageFormatException was handled popup.

Could not load file or assembly 'mcp2210_dll_m_dotnetv2_x86, Version=1.0.5980.19136, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. Why is this happening?

John Wu

Namespace has nothing to do with a DLL's name. Just because the DLL is named mcp2210 doesn't mean it contains the namespace mcp2210.

After you've added the reference, open Visual Studio's object browser. Find the DLL in the treeview on the left and expand it to discover the namespaces and classes contained in it.

enter image description here

Once you find it, use one of its namespaces in your using statement and you're good to go.

If you cannot browse to your DLL, it is probably the wrong type of DLL or the wrong framework version.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related