1

I am used FieldTalk Modbus in .Net. When i run the application i am getting error at creating the object for MbusTcpMasterProtocol.

MbusTcpMasterProtocol mbusProtocol = new MbusTcpMasterProtocol();

The error is:

Native DLL libmbusmaster.dll is missing! Please deploy the DLL file into the same directory as mbusmaster.net.dll.

I added libmbusmaster.dll as "ExistingItem" in to the project and mbusmaster.net.dll as refrence to the project.

  • 1
    So have you verified the two dlls are in the same place? (and the place your application loads them from) – Alex K. Mar 27 '15 at 12:37
  • Yes both are in same location(inside bin->debug), when i add the libmbusmaster.dll as a reference, i am getting error as "D:\xxx\bin\Debug\libmbusmaster.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component." – Vanaja Mitta Mar 27 '15 at 12:52
  • for the reason i added "libmbusmaster.dll" as an "ExistingItem(right click on project->add -> ExistingItem)" – Vanaja Mitta Mar 27 '15 at 12:54

2 Answers2

0

Adding "libmbusmaster.dll" to your project is not getting it added to the same folder where "mbusmaster.dll" is located. You specified mbusmater.dll is located in the "debug" folder. When you added "libmbusmaster.dll" to your project, it probably got added to the root folder of your project (not into debug). To get it added to debug, go to the properties of "libmbusmaster.dll" in your solution, and select "Copy Always" or "Copy if Newer".

Russ
  • 4,091
  • 21
  • 32
  • Thanks for your reply. I already tried with "Copy Always" option, but no luck I am getting the same issue.It is showing the path as "D:\xxx\xxxService\libmbusmaster.dll" not in "debug" folder. – Vanaja Mitta Mar 28 '15 at 06:01
0

The mbusmaster.net.dll uses a relative dll import [DllImport("libmbusmaster.dll")]

This means that it will try to load the libmbusmaster.dll from wherever the entry assembly is located, not wherever the mbusmaster.net.dll is located.

For most programs, the entry assembly path and the mbusmaster.net.dll path will be the same. However if you have an application that say, loads plugins from other folders, and a plugin uses these assemblies, the plugin will have to use the SetDllLocation technique described here

StingyJack
  • 19,041
  • 10
  • 63
  • 122